I am creating a text file using CFile Object. The code is as below:
CFile filePtr.
CFileException e;
CString fileName = "textfile.txt";
CString data;
if( filePtr.Open( fileName.operator LPCTSTR(), CFile::modeCreate | CFile::modeWrite, &e) )
{
// do something if error occurs
}
data = "This is the first Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
data = "This is the Second Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
data = "This is the Third Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
filePtr.Close();
When i open the file created using notepad, the 3 sentences are in the same line. The new line character '\n' is displayed as some black rectangle character.
If i open the same file in Word Pad, it is displayed in 3 different lines as expected.
I cannot understand what is problem. Is there any solution to this?
In my system, the users will use a notepad to open the file.
Please help.
Thanks in advance.
raochetan
CFile filePtr.
CFileException e;
CString fileName = "textfile.txt";
CString data;
if( filePtr.Open( fileName.operator LPCTSTR(), CFile::modeCreate | CFile::modeWrite, &e) )
{
// do something if error occurs
}
data = "This is the first Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
data = "This is the Second Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
data = "This is the Third Line of Test.\n";
filePtr.Write( data.operator LPCTSTR(), data.GetLength() );
filePtr.Close();
When i open the file created using notepad, the 3 sentences are in the same line. The new line character '\n' is displayed as some black rectangle character.
If i open the same file in Word Pad, it is displayed in 3 different lines as expected.
I cannot understand what is problem. Is there any solution to this?
In my system, the users will use a notepad to open the file.
Please help.
Thanks in advance.
raochetan