首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于vc储存串口传来的数据有关问题

2012-01-24 
关于vc储存串口传来的数据问题现在已经完成串口通讯数据处理后存在变量中请问如何将实时传来的数据保存在

关于vc储存串口传来的数据问题
现在已经完成串口通讯     数据处理后存在变量中     请问如何将实时传来的数据保存在一个txt文件中阿     如果有具体的程序更好   急用拜谢

[解决办法]
CString strFileName = " ";
strFileName.Format( "输出文件.txt ",strTextName);
ofstream outFile(strFileName,ios_base::out | ios_base::app);
if (!outFile.good())
{
cerr < < "Error while opening output file " < < endl;
return -1;
}

CString str = " ";
把读到的内容格式为想要的内容存放在str中
outFile < < str < < endl;
[解决办法]
用CFile比较简单

CFile destFile;
CFileException ex;
CStringpath; //txt文件保存路径
char buf[1024];//缓冲区变量,大小根据实际情况

...

if (!destFile.Open(path,
CFile::modeWrite|
CFile::shareExclusive|
CFile::typeBinary|
CFile::modeCreate, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
::AfxMessageBox(szError);
return;
}

destFile.Write(buf, sizeof(buf));

destFile.Close();

热点排行