carriage return in CFile::Write
-
I'm logging errors to a text file, and the text has the 'r\n\' escape characters in there, but it still keeps writing to one continuous line. How do I stop this? If it's broken, I probably did it bdiamond
Hi, I just tried this
CString s = "First line\r\n";
CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite);
file.Write(s, s.GetLength());
s = "second line";
file.Write(s, s.GetLength());and this is what I see in the text.txt file
First line second line
Do you see something I did differently? Fabian -
Hi, I just tried this
CString s = "First line\r\n";
CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite);
file.Write(s, s.GetLength());
s = "second line";
file.Write(s, s.GetLength());and this is what I see in the text.txt file
First line second line
Do you see something I did differently? Fabianyes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond
-
yes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond
The seek to end may be truncating the \r\n on the final line. Try adding a \r\n pair to the beginning of your string. Brad
-
yes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond
-
Hi, How about this?
CString s = "\r\none more line";
CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);
file.SeekToEnd();
file.Write(s, s.GetLength());Fabian
-
I'm logging errors to a text file, and the text has the 'r\n\' escape characters in there, but it still keeps writing to one continuous line. How do I stop this? If it's broken, I probably did it bdiamond
bdiamond wrote: text has the 'r\n\' I hope this is a typo and you actually have '\r\n'.... Elaine :rose: The tigress is here :-D
-
bdiamond wrote: text has the 'r\n\' I hope this is a typo and you actually have '\r\n'.... Elaine :rose: The tigress is here :-D