std::ostringstream and \r\n

  • Thread starter Olaf van der Spek
  • Start date
O

Olaf van der Spek

Hi,

I'm using ostringstream and I'd like to generate \r\n line ends
instead of \n ones.
Is there a flag for this?
Or should I just insert the \r myself?
 
T

Tilman Kuepper

Hello Olaf,
I'm using ostringstream and I'd like to generate \r\n line ends
instead of \n ones. Is there a flag for this?

I don't think there is a flag...

If you are on a Windows box, "\n" will be converted to "\r\n" when
writing ***to a file*** (that is opened in "text mode"). And vice versa.
If you really need character-strings with "\r\n" line endings (why?)
you would have to convert the line-endings "manually".

Please note that line-endings are platform-specific; IIRC Windows
uses "\r\n", Linux "\n", Macintosh "\r" etc. Thus, you better just
open your text files in "text mode" and let the Standard Libary
(or the operating system) do The Right Thing (tm).

Best regards,
Tilman
 
O

Olaf van der Spek

Hello Olaf,


I don't think there is a flag...

If you are on a Windows box, "\n" will be converted to "\r\n" when
writing ***to a file*** (that is opened in "text mode"). And vice versa.
If you really need character-strings with "\r\n" line endings (why?)
you would have to convert the line-endings "manually".

I'm first writing the document to memory in my own code and then to
file via MFC.
 
O

Old Wolf

Olaf said:
I'm first writing the document to memory in my own code and then to
file via MFC.

You should instruct the MFC stuff to open the file in text mode.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top