Carriage return(\n) in CStrings

Started by
5 comments, last by Telamon 23 years, 6 months ago
I''m using MFC and have a CString attached to an Edit Box. I have set the multiline property to true and would like to show multiple lines of text now. Of course, \n doesn''t work with CStrings like it does in C Strings. I checked all the help files that came with VC++ and couldn''t find the answer. Microsoft bastards. Do I need to make a C String and then transcribe it into a CString to get carriage returns?! I''m sure I''m missing something here. ----------------------------- Let be be finale of seem, seems to me.

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Advertisement
try using endl. I dunno if it''ll work with CString & MFC but this is how you use it with regular C++:

cout << "hello" << endl;

==============================
\\// live long and prosper; \||/ die short and rot.
==============================

Drew Sikora
Executive Producer
GameDev.net

I''m quite certain that CStrings can hold newlines-- I use them all the time to store blocks of text. In fact, I think CStrings are one of the few things that MFC got right-- they are a pretty efficient construct.

So I bet the problem has to do with the edit control''s handling (mangling) of the string. If you post some code I''ll take a look.
Try \r\n

This should work

Regards Erik

I''m just posting to second Erik''s suggestion. ''\n'' isn''t a universal newline.

Under Windows based systems, a full newline is traditionally ''\r\n''. ''\n'' is, however, a full newline under UNIX (and some other) systems.
I had that same exact problem with a console mode game I''m working on. And yes, \n\r was how I had to fix it.

shut up
CAN I GET A WOO WOO!

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Yep! \r\n did the trick. Thanks again everybody! This is a great place to get help for these quirky kind of questions :-)

-----------------------------
Let be be finale of seem, seems to me.

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

This topic is closed to new replies.

Advertisement