ostringstream and ostream

Started by
14 comments, last by Fruny 19 years, 7 months ago
They should, unless you have a funky definition of 'a line down'.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
I want to do something like this:
File<<"LineA"<<endl
File<<"LineB"

and get the result in file:
LineA
LineB

but instead I get the result of:
LineALineB
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
My code is something like this:

void
LogFile::WriteLine (string Line)
{
if (this->bWriteEnable)
{
ofstream File(this->FileName.c_str(), ios::binary | ios::app);

File<<this->LineNumber<<": "<<Line<<endl;
this->LineNumber++;

File.close();
}
}

LogFile LF("log.fl");

LF.WriteLine ("LineA");
LF.WriteLine ("LineB");

However I get LineALineB instead of:
LineA
LineB

I also tried to put the endl at the begining like this:
File<<endl<<this->LineNumber<<": "<<Line;

Doesnt work either.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Why are you opening the file in binary mode?
On MS platforms, an end-of-line is marked by \r\n.

Opening in text mode enables the translation file(\r\n)<->memory(\n), while opening in binary mode disables it.

Unless you really are manipulating binary data (which must not be translated), you have little reason to open the file with an std::ios::binary flag.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ok, the problem is when I open the file with notepad it doesnt do the line downs.
However, with word pad I do see the lines one under the other.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Quote:Original post by The C modest god
Ok, the problem is when I open the file with notepad it doesnt do the line downs.
However, with word pad I do see the lines one under the other.


That's because wordpad is smarter than notepad, and is able to deal with UNIX end-of-line conventions (i.e. just a '\n' in the file).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement