Im wriitng some data in File.But it doesnot write this properly.
Code:
CString sFileName = "C:\\Test.txt";
CFile gpFile;
CString testarr[10] = {"Tom","Ger","FER","DER","SIL","REM","FWE","DWR","SFE","RPOP"};
if (!gpFile.Open( sFileName,CFile::modeCreate|CFile::modeWrite))
{
AfxMessageBox( sFileName + (CString)" - File Write Error");
return;
}
else
{
gpFile.Write(testarr,10);
}
AfxMessageBox("Completed");
gpFile.Close();
It shows the file as

That’s probably because you’re using
CFileincorrectly. The first parameter toCFile::Writeshould be a buffer whose bytes you’d like to write to the file. However,testarris more like a “buffer of buffers”, since each element oftestarris a string, and a string is itself a sequence of bytes.What you would need to do instead is either concatenate the elements of
testarr, and then callCFile::Write. Or (probably more practical), iterate overtestarrprinting each string one at a time, e.g. for your particular example, the following should do what you’re looking for:There may be some built-in way to accomplish this, but I’m not really familiar with MFC, so I won’t be much help there.