skipping # sign in an infile

how do you skip # from this code in order to know the name and the price name?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
		ifstream inFile;
		string item;
		int price;
		inFile.open("invoice1.txt");
		inFile  >> item>>price;
			
				
		
		
			cout << "Please input the item's name input 999 to stop the program: \n";
			cin >> item;

			while ( item != "999" )
			{
            cout << "the price of the " << item << ": ";
            cout<< price<<" \n";
           
            
            cout << "Please input the item's name input 999 to stop the program: \n";
			cin >> item;

			}
			cout << "\nThank you for your order.\n";
			
return 0;
}
I cleaned up your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <fstream>
#include <string>

int main ( )
{
	std::ifstream fin ( "invoice1.txt" );

	if ( !fin )
	{
		std::cout << "The file could not be opened.\n";

		return 0;
	}


	std::string item;

	int price;

	fin >> item >> price;


	do {
		std::cout << "Please input the item's name. Input 999 to stop the program.\nItem Name: ";
		std::cin >> item;

		if ( item != "999" )
			std::cout << "\nThe price of " << item << " is: " << price << "\n\n";
	} while ( item != "999" );


	std::cout << "\nThank you for your order.\n";
}

What is this program supposed to do, and what is in invoice1.txt?
this program i supposed to search a tool in the invoice.txt file and state the price of the said tool.
and if you entered an invalid name of the tool, it will be invalid.

The invoice1.txt contains :
hammer#9.95
saw#20.15
shovel#35.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <fstream>
#include <string>
#include <vector>


typedef std::vector<std::pair<std::string,float>> DATA;


bool readFile ( std::string fileName, DATA & data );

bool isItem ( const DATA & data, std::string item );

float getPrice ( const DATA & data, std::string item );


int main ( )
{
	DATA data;

	std::string item;


	if ( !readFile ( "invoice.txt", data ) )
	{
		std::cout << "The file could not be opened.\n";

		return 0;
	}


	do {
		std::cout << "Please input the item's name. Input 'Stop' to stop the program.\nItem Name: ";

		std::cin >> item;

		if ( item != "Stop" )
		{
			if ( isItem ( data, item ) )
				std::cout << "\nThe price of a " << item << " is $"
				<< getPrice ( data, item ) << "\n\n";

			else std::cout << "\nThat is not an item.\n\n";
		}
	} while ( item != "Stop" );


	std::cout << "\nThank you for your order.\n";
}


bool readFile ( std::string fileName, DATA & data )
{
	std::ifstream fin ( fileName );

	if ( !fin ) return false;


	std::string item;

	float price;


	while ( fin.peek ( ) != EOF )
	{
		getline ( fin, item, '#' );

		fin >> price;

		fin.ignore ( );

		data.push_back ( make_pair ( item, price ) );
	}


	return true;
}


bool isItem ( const DATA & data, std::string item )
{
	size_t items = data.size ( );

	for ( size_t i = 0; i < items; ++i )
		if ( data[i].first == item )
			return true;

	return false;
}


float getPrice ( const DATA & data, std::string item )
{
	size_t items = data.size ( );

	for ( size_t i = 0; i < items; ++i )
		if ( data[i].first == item )
			return data[i].second;
}
Topic archived. No new replies allowed.