We know that when inserting \n
in a file stream, the appropriate end-of-line sequence for the system will be written to the file (e.g. \r\n
for Windows). Does inserting an endline in a std::stringstream
result in the system-appropriate end-of-line sequence being written to the string? For example:
#include <sstream>
int main()
{
std::ostringstream oss;
oss << std::endl;
std::string endlineSequence = oss.str();
bool isWindows = enlineSequence == "\r\n";
bool isOldMac = endlineSequence == "\r";
bool isUnix = endlineSequence == "\n";
// Will this work???
}
bool
s in your program aretrue
or not... most likelyisWindows
andisMac
will evaluate tofalse
. – Streetwalker\n
and get\r\n
, it does the translation to native newline; and if you get\n
it doesn't. It's not noticeable in Linux or MacOS X, though. – Weal