读书人

怎么按照固定的格式将一些内容写入文件

发布时间: 2012-01-16 23:36:51 作者: rapoo

如何按照固定的格式将一些内容写入文件中?
格式是这样的:
*** Edit1中的内容
*** Edit2中的内容。

[解决办法]
那就写吧,有问题吗?
[解决办法]
将你获得的edit的内容前加上 "*** ".写入文件,就行了,哪里有问题呢?
[解决办法]
写文件用C的也可以
[解决办法]
CFile file( "1.txt ",CFile::modeWrite);
file.Write( "abc ",strlen( "abc "));
file.Close();
[解决办法]
CFile cfile( "文件名 ",CFile::modeCreate|CFile::modeWrite );
CString str;
GetDlgItem(Edit n 的ID)-> GetWindowText(&str);
str = CString( "*** ") + str;
cfile.Write( str.GetBuffer(), str.Length());
cfile.Close();
差不多就这样

[解决办法]
用ini格式文件,
有现成的函数读取

[section]
***=Edit1中的内容
***=Edit2中的内容

GetPrivateProfileString

The GetPrivateProfileString function retrieves a string from the specified section in an initialization file.

Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.


DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
);


[解决办法]
CFile WFile;
if(WFile.Open( "C:\\MyFile.dump ",
CFile::modeCreate|CFile::modeReadWrite|CFile::typeText))
{
CString str;
GetDlgItem(IDC_EDIT1)-> GetWindowText(str);
str = CString( "*** ") + str;
file.Write( str,str.GetLength());
}
file.Close();

读书人网 >VC/MFC

热点推荐