For some reason, my write-to-textfile function stopped working all of a sudden.
void write_data(char* filename, char* writethis)
{
ofstream myfile;
myfile.open (filename, std::ios_base::app);
myfile << endl << writethis;
myfile.close();
}
The function was called from a loop, so basically it started with an empty line and appended all the following "writethis" lines on a new line.
Then all of a sudden, no more newlines. All text was appended on one single line. So I did some digging and I came across this:
- Windows = CR LF
- Linux = LF
- MAC < 0SX = CR
So I changed the line to
myfile << "\r\n" << writethis;
And it worked again. But now I'm confused. I am coding on linux but I am reading the textfiles created with the program out on windows after transferring them with filezilla. Now which part of this caused the lines in the textfile to appear as one line?
I was pretty sure "endl" worked just fine for linux so now I'm thinking windows messed the file up after transferring them with filezilla? Messing up the way the text file is written to (and read out) will guarantee my program to break, so if someone can explain this I'd appreciate it.
I also don't recall what I changed in my program to cause this to break, because it was working just fine earlier. The only thing I added was threading.
Edit:
I have tried swapping the transfer mode from ASCII / Binary (even removed the force-ASCII-for-txt-extension), but it makes no differences. The newlines appear in linux, but not on windows.
How odd.