Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Cross-platform newline character in string

When newline in string is necessary, I use the \n character

 int main()
 {
     string str = "Hello world\n";
 }

Is \n crossplatform? Or do I need to use macro adapting it's value with the platform?

Especially when str is going to be written to a file or stdout.

like image 652
Abdillah Avatar asked Jan 21 '16 03:01

Abdillah


1 Answers

As long as you read/write text streams, or files in text mode, \n will be translated into the correct sequence for the platform.

http://en.cppreference.com/w/c/io

like image 50
axl Avatar answered Sep 22 '22 04:09

axl