a problem with file

hii i am new to c++ i have a problem with files. when i read from file the words appear on console without spaces and also i can't make a new line when reading from file plz help me. thanks in advance
Post the code you're having trouble with in [code]source code here[/code] tags.
here are the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
   ifstream myReadFile;
 myReadFile.open("all_grades.txt");
 char output[200];
 if (myReadFile.is_open())
  {
 while (!myReadFile.eof())
  {

   myReadFile>>output;
   
    cout<<output;


 }
}
myReadFile.close();
system("pause");
    return 0;}
Post up how you have the data stored in the all_grades.txt file as well.
i have it all in one line
Show me the contents though. Like are the grades stored like 'ACABEDCABECABC'?
no its stored like this 'a b c d e' but it appear on console like this'abcde'
If thats the case, why don't you just add a space. Considering all you want is the output to be separated?

cout << output << " ";
ok that's great thank you but if i file contains statement like this'i went to my college. i meet my friend' how can i make each statement in a line thanks in advance
You could do something like this which reads a line inside the file:

http://cplusplus.com/reference/iostream/istream/getline/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	ifstream myReadFile;
	myReadFile.open("all_grades.txt");
	char output[256];
	if (myReadFile.is_open())
	{
		while (!myReadFile.eof())
		{
			myReadFile.getline(output, 256);
			cout << output << "\n";
		}
	}
	myReadFile.close();
	system("pause");

	return 0;
}
Topic archived. No new replies allowed.