Newline Return Character


djcool3005

Still Fresh
Joined
Jan 21, 2012
Messages
3
What is the newline return character on the Caanoo? I am creating a log file in my game that has all debug output written to it. I am using \n and on the PC (Windows 7) it works perfectly fine. However on the Caanoo it puts everything on one line :S

As a very basic example I have something similar to this in my game:

Code:
ofstream logfile;

logfile.open("log.txt");

logfile << "This file will contain any debug outputs from the game. \n";

//Then when the game is closed this happens

logfile << "Game was closed successfully.";
logfile.close();


On the pc the log.txt file is like this:
Code:
This file will contain any debug outputs from the game. 
Game was closed successfully.

On the caannoo however it is all on one line like this:
Code:
This file will contain any debug outputs from the game. Game was closed successfully.

I know you may be thinking this isn't so bad but I have lots of other calls to write to the log file and it soon becomes unreadable when everything is put on one line.

So basically what is the newline character I need to be using for it to work properly on the Caanoo?

Thanks
 
What do you mean with 'on the Caanoo'? Maybe the app you're using to show the text does not support Unix-style ("\n") line termination. Try DOS-style instead: "\r\n". Or look for a better app ;-)
 
"\n" is valid only using stdio ?printf, it have no meaning in c++ stream.
It look like MS have extended the norm. The correct way is to use :
Code:
logfile << "This file will contain any debug outputs from the game." << endl;
logfile << "Game was closed successfully." << endl;
 
"\ņ" is valid in *any* string literal, it has nothing to do with C++ or streams or printf. Also std::endl will still turn out as "\n" on the Caanoo, so it will not make a difference for this purpose.
 
hmn said:
"\ņ" is valid in *any* string literal, it has nothing to do with C++ or streams or printf. Also std::endl will still turn out as "\n" on the Caanoo, so it will not make a difference for this purpose.
Sure You can put anything in a string, yet I'm sure endl works (as I have used it) and I never used "\n" with stream myself, but google confirm what hmn say... my bad
 
Last edited by a moderator:
hmn said:
What do you mean with 'on the Caanoo'? Maybe the app you're using to show the text does not support Unix-style ("\n") line termination. Try DOS-style instead: "\r\n". Or look for a better app ;-)

By on the Caanoo I mean like when I run the game on the Caanoo and then close it, plug the USB cable in and inspect the log file, it turns out differently from when I run it on the pc and check the logfile. Anyways it seems \r\n works on the Caanoo and on the PC so problem solved. Strangely something I discovered is that if I deleted the log file that's on the Caanoo and then unplug USB and run the game again without powering off the Caanoo first it doesn't make a new log file :S I had to turn it off and turn it on again and then run the game again for it to create a log file :S
 
Last edited by a moderator:
Ahhh understund now, you were checking the log under windows... So yeah like the old printers, windows need you to tell it to return carriage (\r) and then get to the new line(\n) xD
 
Yeah it just seems strange that when I run the game on Windows the log file it produced turned out fine just using \n and then the log file that was produced by the Caanoo would have everything on one line. I guess whatever version of Linux that the Caanoo uses must need \r\n for it to work correctly.
 
djcool3005 said:
Yeah it just seems strange that when I run the game on Windows the log file it produced turned out fine just using \n and then the log file that was produced by the Caanoo would have everything on one line. I guess whatever version of Linux that the Caanoo uses must need \r\n for it to work correctly.
The other way around. Linux don't need the \r, so it doesnt add it to the file, but as _most_ text reader under windows need them, I guess windows add them automatically. Open the file only containing \n with wordpad if you dont trust me : it works ;)
 
Last edited by a moderator:
djcool3005 said:
Yeah it just seems strange that when I run the game on Windows the log file it produced turned out fine just using \n and then the log file that was produced by the Caanoo would have everything on one line. I guess whatever version of Linux that the Caanoo uses must need \r\n for it to work correctly.
Other way around. It is working fine in Linux with just \n, but since Windows (often) needs \r\n, with the Caanoo only outputting \n it will look weird.
The reason it appears to work in Windows when you are just using \n is because a lot of compilers will secretly convert \n to \r\n. It appeared to work in Windows because it was outputting the \r required by Notepad to display properly, but the Caanoo, which doesn't need the \r, didn't put the \r.
If you want to view the log files on a Windows machine, then you will have to explicitly put the \r\n, or you can use endl as already recommend and most importantly you should stop using Notepad to read log files.

edit: Wow, ninja'd by several hours. How did I miss that? Seriously weird. Pay me no attention.
 
Last edited by a moderator:
Back
Top