Is there a platform independent JUCE endline item, like “std::endl” but as a juce::String?

I get errors when using std::endl like this, so was looking for “the JUCE way”:

String foo;
foo << "Bar" << std::endl;

I assume that would be newLine.
Though you shouldn’t get errors with something as basic as STL stuff.


Brilliant, thanks!

String foo;
foo << “Bar” << std::endl;


error: no match for ‘operator<<’ in ‘juce::operator<<(((juce::String&)(& foo)), ((const char*)“Bar”)) << std::endl’[/code]

OMG, please bury the C++ idiotic sh*t that cin/cout provides.
Stick a “\n” in there, and do not use the << operator for anything that’s coming from / going to user output.

You’ll eat your hat twice if you either need to translate a code doing “cout <<”. First when you’ll have to rewrite everything once you have a French/Chinese/whatever customer, and the second time, when people will use an external plugin that’s changing the cout’s state (like making the number conversion using hexadecimal, it’s very funny to debug).

Sure, but slightly OT?

I’m not using cout, I’m formatting a String with the << operator from the String class. What I needed was ‘newLine’ to avoid std::endl.

I see JUCE code using a lot of <<, look at juce_core/network/juce_URL.cpp for instance. Any problems with code like this?:

String foo;
foo << "Bar" << newLine;

On your topic, if std::cout is bad, how do you propose writing to stdout - fprintf()?

For windows, I don’t see the point since you don’t have a stdout that’s shown.

For posix systems, for small - temporary things, I’m inclined to use write or fputs.
The Juce’s way is to use Logger::outputDebugString or writeToLog depending on your target, and the string passed in should be created with String::formatted(TRANS(“your message with %s”)), someParam);

The former allows redirecting the output to whatever stream you want without changing a single line of code in your application (good luck doing so with cout), the latter is cleaner and safe for translation.