reading text from a file

Im trying to read text from a file and display it such as:

Instructions
1. Blahblahblah
2. blahablahblah
3. blahblahblah

As of right now the text appears in a constant string. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
case '2': instructFile.open("instructions.txt");
			
			if (!instructFile)
				cout << "Error opening file.\n";

			else
			{
				instructFile >> instruction;
			
				while (!instructFile.eof())
				{
					cout << question << " ";
					instructFile >> instruction;

				}
				cout << endl;
				instructFile.close();
			}
			cout << "Press any button to go back";
		
			break;
move line 17 to line 13
closed account (Dy7SLyTq)
how will that help? what you need is getline(instructFile, instruction);
What is question (line 12)?

Something like this is better than using eof()
1
2
3
4
    while (getline(instructFile, instruction))
    {
        cout << instruction << endl;
    }
Last edited on
Topic archived. No new replies allowed.