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???
}
The system specific line endings are only relevant for text files. As long as the stream is only in memory, it is just '\n'
.