Online and other emergency CString txt file output to the output I do have a problem ofstream

Category: VC/MFC -> Foundation Classes Author: zxc13952021010 Date: 2010-06-20 19:08:34
 
zxc13952021010
2010-06-20 19:08:34
Operating environment visual   studio   2005

code is as follows :
CString   s = _T (" la la la abcdef ");
std :: ofstream   outfile (_T ( " aaa.txt "), ios :: out);
outfile < < s;
out.close (); result

output : 003AFF78

feeling is that the problem is not encoding ?   My computer seems to use the unicode. The same 2005 code up and running on my computer seems to not work. For example, I can not use atoi only with _tstoi etc.  .

Ask how to solve , thank you !   Online
yedipo
2010-06-20 19:24:16
CString   s = _T (" la la la abcdef ");
s.GetBuffer (s.GelLength ());
std :: ofstream   outfile (_T (" aaa.txt "), ios :: out);
outfile < < s;
out.close ();
s.ReleaseBuffer ();
jiangan0826
2010-06-20 19:38:25
thanks reply ! But try the   in aaa.txt output is still 003AFF78 ....

I later changed tried   outfile < < s.GetAt (0);   resulting output to aaa.txt in the " friends " 's asci code
suyong13
2010-06-20 19:47:48
and   on my computer   string   s1 = s.getString (); nor can .. nor can CString   converted to char *   only turn TCHAR * ...

really impatient ! ! ! Hope to help !
HO_HO
2010-06-20 19:59:03
Why is no one answer it .... problem is very troublesome it?
cte1661
2010-06-20 20:01:44
I have the same problem when using CArchive << will be out of the question , the direct use CFILE the WRITE method but not garbled, seeking expert explained
By the way , is UNICODE.
dasgourab
2010-06-20 20:12:00
You can put the code into unicode character encoding , gbk232  , can !
ice09650683yy
2010-06-20 20:16:26
output is the address ......
string   s1 (s.GetBuffer ());
s.ReleaseBuffer ();
outfile < < s1;
this a try.
In fact, it is best not to mix MFC and STL.
FENGSHAJORDAN
2010-06-20 20:20:07
CString   s = _T (" la la la abcdef ");
std :: ofstream   outfile (_T (" aaa.txt "), ios :: out);
outfile < < (LPCTSTR) s;
out.close ();
guojunqing7441
2010-06-20 20:25:07
The last one is a positive solution ! ! !
xiaoqiong0419
2010-06-20 20:29:19
is not a project is established, encoding settings are : Unico coding , does not use multiple character sets.
there may indeed have been defined using the header files Unico encoding, so no matter how set up , the results are Unico encoding.
qq452838891
2010-06-20 20:42:28
void   LogInfo (CString   szLog)
{

FILE *       fp           =   NULL  ;
char *       pLog       =   NULL  ;
int           nPos       =   0        ;  
int           i             =   0        ;
int           iLen       =   0        ;
CString   sPath     =   " "      ;
CString   szLog1   =   " "      ;
CTime       tNow       =   CTime :: GetCurrentTime   ()  ;
CString   cNow1     =   tNow.Format ("% Y-% m-% d ")    ;
CString   cNow       =   tNow.Format ("% Y-% m-% d  % H:% M:% S ")  ;

GetModuleFileName (NULL, sPath. GetBufferSetLength (MAX_PATH + 1), MAX_PATH)  ;
sPath.ReleaseBuffer ();
nPos   =   sPath.ReverseFind ('\\');
sPath   =   sPath.Left (nPos + 1);

szLog1 = cNow + " \ t " + szLog + " \ n ";
pLog   =   (char *) (LPCTSTR ) szLog1;
fp   =   fopen (sPath + cNow1 + " .txt ", " a ");
iLen = strlen (pLog);
while   (pLog [ i])
{
fputc (pLog [i], fp);
        i ++;
}
fclose (fp);   //   emptied resources
}
w8713015050275
2010-06-20 20:44:55
void   LogInfo (CString   szLog)
{

FILE *       fp           =   NULL  ;
char *       pLog       =   NULL  ;
int           nPos       =   0        ;  
int           i             =   0        ;
int           iLen       =   0        ;
CString   sPath     =   " "      ;
CString   szLog1   =   " "      ;
CTime       tNow       =   CTime :: GetCurrentTime   ()  ;
CString   cNow1     =   tNow.Format ("% Y-% m-% d " )    ;
CString   cNow       =   tNow.Format ("% Y-% m-% d  % H:% M:% S ")  ;

GetModuleFileName (NULL, sPath.GetBufferSetLength (MAX_PATH + 1), MAX_PATH)  ;
sPath.ReleaseBuffer ();
nPos   =   sPath.ReverseFind ('\ \ ');
sPath   =   sPath.Left (nPos + 1);

szLog1 = cNow + " \ t " + szLog + " \ n ";
pLog   =   (char *) (LPCTSTR) szLog1;
fp   =   fopen (sPath + cNow1 + " .txt ", " a ");
iLen = strlen (pLog);
while   (pLog [i])
{
fputc (pLog [i], fp);
        i ++;
}
fclose (fp);   //   emptied resources
}