I'm using the following code to read in data to a file.
When I read out the file, the data is being outputed underneath each other like this:
1
2
3
I want to read it out like this:
1 2 3
This is my code:
Code:#include <iostream.h> #include <fstream.h> void main(){ ofstream OutFile("test.txt"); OutFile << "Hello world!"; OutFile.close(); OutFile.open("numbers.txt"); OutFile << 15 << " " << 42 << " " << 1; OutFile.close(); ifstream InFile; InFile.open("test.txt"); char p[50]; InFile >> p; cout << p << endl; InFile >> p; cout << p << endl; InFile.close(); int TempNum; InFile.open("numbers.txt"); while (!InFile.eof()) { InFile >> TempNum; if (!InFile.eof()) cout<< TempNum << endl; } InFile.close(); InFile.open("test.txt"); while (!InFile.eof()) { InFile >> p; cout << p << endl; } }




Reply With Quote