PDA

View Full Version : qtextstream & qstring



mickey
24th February 2006, 11:52
text ="left\n";
text =text +"right\n";
QFile f(file);
f.open(IO_WriteOnly);
QTextStream xstrm(&f);
xstrm << text;
f.close();
I thought that this code produce a file so:


left
right

Instead:


leftright
how can I do? thanks.

fullmetalcoder
24th February 2006, 11:59
it seems you forget a flag in the open method of your file.

in Qt4 the flag is QIODevice::Text, so in Qt3 it should be something like IO_Text

on Windows, line breaks aren't only "\n" but actually "\r\n"

wysota
24th February 2006, 12:03
One should use endl() to write a newline to the stream instead of using \n.

yop
24th February 2006, 20:18
One should use endl() to write a newline to the stream instead of using \n.
Because windows consider a new line to be "\n\r" , they just can't figure out that computers are not typewriters anymore :p