0

Is there a way to print a platform specific newline (Linux in this case) to the standard output regardless of the platform the program is running on (Windows in this case)?

Same question as this, but I want to write to the standard output instead of writing to a file.

Edit because marked as duplicate: This question and its answers does not contain information about the newline translation effect of changing to binary mode. So the answer to my question is the combination of the aforementioned two questions.

Community
  • 1
  • 1
bati06
  • 307
  • 2
  • 10
  • Set the ios::binary flag on std::cout. – Sam Varshavchik Jan 07 '17 at 03:23
  • @SamVarshavchik but how do you do that? The flag is generally set when you open the file, but `cout` is already open when your program starts. – Mark Ransom Jan 07 '17 at 03:38
  • http://stackoverflow.com/questions/23107609/is-there-way-to-set-stdout-to-binary-mode – Sam Varshavchik Jan 07 '17 at 03:58
  • @SamVarshavchik that question speaks of `stdout` not `cout`, so it's not clear that it addresses my concern. But since this question never specified which one they're trying to use, I'll let it slide. – Mark Ransom Jan 08 '17 at 02:40
  • @bati06 the whole point of binary mode is that it doesn't do any translation whatsoever. So if writing a `\n` on Windows results in `\r\n` appearing in the output in text mode, in binary mode you're guaranteed to just get `\n`. – Mark Ransom Jan 08 '17 at 02:42
  • @MarkRansom Thanks. Its clear now. – bati06 Jan 08 '17 at 13:53

0 Answers0