CFile and Linefeed
-
Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?
CFile cFoo;
cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
{
cFoo.Write(_T("TEST\n"), 5);
cFoo.Write(_T("TEST2\n"),6);
cFoo.Write("TEST3\n",6);
}
cFoo.Close();Thanks Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
-
Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?
CFile cFoo;
cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
{
cFoo.Write(_T("TEST\n"), 5);
cFoo.Write(_T("TEST2\n"),6);
cFoo.Write("TEST3\n",6);
}
cFoo.Close();Thanks Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
Maybe you need to add the \r carrage return?
cFoo.Write(_T("TEST\n\r"), 6);
Does that work??
-
Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?
CFile cFoo;
cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
{
cFoo.Write(_T("TEST\n"), 5);
cFoo.Write(_T("TEST2\n"),6);
cFoo.Write("TEST3\n",6);
}
cFoo.Close();Thanks Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
Hey Colin I just noticed when you open the file the option CFile::typeText is not specified. MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.write.asp Also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.cfile.asp "CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only)." You should get your carrage returns then. Also carrage return\linefeed is counted as one character. Hope I helped. :)
-
Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?
CFile cFoo;
cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
{
cFoo.Write(_T("TEST\n"), 5);
cFoo.Write(_T("TEST2\n"),6);
cFoo.Write("TEST3\n",6);
}
cFoo.Close();Thanks Regardz Colin J Davies
Sonork ID 100.9197:Colin
More about me :-)
Because a "newline" in DOS/Windows is "\r\n" not just "\n". FYI, if you use CStdioFile::WriteString(), it converts "\n" to "\r\n" on the fly. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
Because a "newline" in DOS/Windows is "\r\n" not just "\n". FYI, if you use CStdioFile::WriteString(), it converts "\n" to "\r\n" on the fly. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
Hey Colin I just noticed when you open the file the option CFile::typeText is not specified. MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.write.asp Also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.cfile.asp "CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only)." You should get your carrage returns then. Also carrage return\linefeed is counted as one character. Hope I helped. :)