using fstream to save files does not save "\r" and "\n"

i'm trying to write a program thats similar to a notepad
when i save a string with characters such as "\r" and "\n" somehow it will get ignored, like if i save a string like this "abcde\rfg", when i view it with notepad it will apear as just abcdefg and not 2 lines
can anyone help me out?

fstream thefile;
thefile.open("OurText.txt", ios::out | ios::binary);
                        
char abc[] = "adsw21\nadwjdaw";

thefile << abc;
                        
thefile.close();
madonion87Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grg99Commented:
The concept of end-of-line is rather loosely defined in the Windows world.  
Traditionally it's CR-LF  "\r\n", but with all the C code getting ported, there's the compatability kludge in the i/o library that if you open the file in non-binary mode the read/write code does the mapping for you.  So try opening the file in text mode and the \n's will get converted (usually).

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteHCommented:
I don't agree that end-of-line is loosely defined. For DOS/Windows based PCs it is "\r\n"! Several editors can open files and if tehy seem to be text they automatically translate single '\r' or '\n' encountered to end-of-line chars. So either go with grg99's comment and write text files or assure that you use "\r\n" on windows as end-of-line marker.
0
SteHCommented:
Sorry wanted to add that Notepad is not one of those smart editors so it won't recognize '\r' as line termination.
0
madonion87Author Commented:
yea got it
this is me testing for another problem though, will post in another question
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.