Run()
{
CFile file;
CString str;
int m_i;//每次调用函数的时候都变化;
char *aa;
str.Format(_T("%d"),m_i);
file.Open("ccc.txt",CFile::modeWrite);file.SeekToEnd();
file.Write(aa,strlen(aa));
file.Close();
}
我现在想问二个问题,
1.当没有ccc.txt文件,就创造然后写,有就只需要写,怎么辨别。
2.怎么把str赋值给aa.
{
CFile file;
CString str;
int m_i;//每次调用函数的时候都变化;
char *aa;
str.Format(_T("%d"),m_i);
file.Open("ccc.txt",CFile::modeWrite);file.SeekToEnd();
file.Write(aa,strlen(aa));
file.Close();
}
我现在想问二个问题,
1.当没有ccc.txt文件,就创造然后写,有就只需要写,怎么辨别。
2.怎么把str赋值给aa.
http://www.csdn.net/Develop/article/16%5C16622.shtm
CString str;
int i=5;
str.Format(_T("%d"),i);
file.Open("ccc.txt",CFile::modeCreate|CFile::modeNoTruncate
|CFile::modeWrite|CFile::shareDenyNone);
file.SeekToEnd();
file.Write(str,strlen(str));
file.Close();
}
怎么来现实二次保存的中间有一个空格。
char cSpace=32;//空格ascii码为32
file.Write(....)
CString 转换为char *使用两次强制类型转换:(LPSTR)(LPCTSTR)这样好像不太妥当。在编码的时候应该禁止这种情况出现。既然使用了CString,那么就不要将其转换为char*类型了。如果一定要转,应该使用const char*。如果有什么API非用char*不可,好的方法应该是新建一个Buffer,然后把字符串复制给它。