# problem with txt files and c++

This topic is 3562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! How do you make an enter in a txt fil from c++? What i mean is that it dosn't look like this: 123456789 instead it should look something like this: 1 2 3 4 . . the cod i'm using is following: fil << "1" << "2" << "3"...... i have tried to put both endl and \n after each sign but it dosen't work. help please!

##### Share on other sites
I got it using both endl and \n:

#include <iostream>#include <fstream>using namespace std;int main(){	ofstream outFile;	outFile.open("test.txt");	outFile << "1\n";	outFile << "2" << endl;	outFile << "3" << endl;	outFile << "4" << endl;	outFile << "5" << endl;	outFile << "6" << endl;	outFile << "7" << endl;	outFile << "8" << endl;	outFile << "9" << endl;        outFile.close();}

Outputs:
1
2
3
...
on my computer.

##### Share on other sites
hello!
works now, had some cod in that wasn't supposed to be their, thanks for you help either way.

##### Share on other sites
Bear in mind that the Windows newline sequence is CRLF; Notepad doesn't handle LF on its own and so will display everything on a single line.

##### Share on other sites
Quote:
 Original post by benryvesBear in mind that the Windows newline sequence is CRLF; Notepad doesn't handle LF on its own and so will display everything on a single line.

C++ streams will do newline conversion for you, unless opened in binary mode.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015448
×