Reading in a file

I am reading in a file that looks like:

append 10
serve
append 20
append 30
serve
push 10
push 50
push 20
push 20
pop
push 50
pop
pop
append 50
append 35
append 25
append 40
serve
append 60
append 70
append 75
append 100
append 200
append 150
push 10
push 50
pop

And I am trying to read it in and do the desired outcome. When it gets to the first 'serve' there is an error. I am thinking it is because there is no number after it so when it assigns it to 'theData' it is not doing it correctly. When I print it, it looks like:
append 10
serve 10
serve 10
serve 10
serve 10
serve 10
serve 10
serve 10
serve 10
etc......

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
	do 
	{				
		if (textFile >> theString >> theData)
		{
			//Stacks
			if (theString == "pop")
			{
				cout << "  Stack     Pop          ---     Success" << endl;
			}

			if (theString == "push")
			{
				cout << "  Stack     Push         "<< theData <<"      Success" << endl;
			}

			if (theString == "top")
			{
				cout << "  Stack     Pop         "<< theData <<"      Success" << endl;  
			}

			//Queue
			if (theString == "append")
			{
				cout << "  Queue     Append       "<< theData <<"      Success" << endl;
				cout << theString << ", " << theData << endl;
			}

			if (theString == "serve")
			{
				cout << "  Queue     Serve        ---     Success" << endl;
			}

		}
		//else if (textFile.fail())
		//{
		//	cout << "The file held incorrect data" << endl;
		//	system ("PAUSE");
		//	exit (1);
		//}

		cout << theString << ", " << theData << endl;

	} while (!textFile.eof());

	textFile.close();


If you could help me with this I would be super grateful. I have tried everything I can think of and I can't find anything online or in my textbook. Thanks!
It seems odd to me you posted this here, 10 minutes after posting http://www.cplusplus.com/forum/beginner/91125/

Inspecting the code there will tell you one way to handle this. serve should be handled similar to pop.
Last edited on
Thank you for pointing that out. I thought I got everything out of it that I code but taking another look at it I saw the issue. I swear I posted that on another forum, but apparently not. Thank you cire. You saved me a lot of headache.
Topic archived. No new replies allowed.