how to write a CString object into a file?
-
Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP
-
Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP
You can use MFC serialization or you can do it directly using MFCC File object
CFile myFile('test.dat', CFile::modeWrite);
CString buff;
buff = "This is some text";myFile.Write(buff, buff.GetLength());
p.s- you can also use Windows SDK functions or the CRT functions so your code works on all platforms (most anyways) HTH Cheers :) The word of the day is legs, let's go back to my house and spread the word ;P
-
You can use MFC serialization or you can do it directly using MFCC File object
CFile myFile('test.dat', CFile::modeWrite);
CString buff;
buff = "This is some text";myFile.Write(buff, buff.GetLength());
p.s- you can also use Windows SDK functions or the CRT functions so your code works on all platforms (most anyways) HTH Cheers :) The word of the day is legs, let's go back to my house and spread the word ;P
hi Thanks for ur reply.Did u check this code,since it is not working. Thanks JP
-
hi Thanks for ur reply.Did u check this code,since it is not working. Thanks JP
Typically code I write here on CP is psuedo code, just to get you started on the right direction, I hardly never test code. try this instead:
CFile myFile('test.dat', CFile::modeWrite);
CString buff;
buff = "This is some text";
myFile.Write(buff.GetBuffer(buff.GetLength()), buff.GetLength());The word of the day is legs, let's go back to my house and spread the word ;P
-
Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP
Try to write like this!
CFile myFile('test.dat', CFile::modeWrite); CString buff; buff = "This is some text"; myFile.Write(str.operator LPCTSTR(),buff.GetLength());
:) Abhishek Srivastava Software Engineer (VC++) India ,Noida Mobile no 9891492921 :) -
Try to write like this!
CFile myFile('test.dat', CFile::modeWrite); CString buff; buff = "This is some text"; myFile.Write(str.operator LPCTSTR(),buff.GetLength());
:) Abhishek Srivastava Software Engineer (VC++) India ,Noida Mobile no 9891492921 :)hi Thanks for ur solution!! But if u use above code..it is not giving any error while executing..but this writes our data with some junk value...So we can't retrieve it properly. Cheers JP:)