-------------------------------
MFC的话,你看是不是用这个
CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Furthermore, if the file being created already exists, the underlying file pointer will point to the beginning of the file. This flag guarantees the file to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
保存到excel中比较麻烦,excel还得有驱动(我在网上下载了个封装好的excel.hexcel.cpp
直接用的,搜了几句代码,功能实现了,不过我没看懂什么意思)。
我一般直接保存到txt中,这个最简单了。
我把数据放到cstring
变量中,然后写入txt的。
1
我把写入txt的函数封装到了
工程.cpp
中了。假设为void
addtotxt(cstring
var)
2
在读取此函数的对话框中,extern
c工程名app
theapp
3
放入数据到txt中
theapp.addtotxt(strtemp)
4.工程.cpp
中的函数体。
cstring
crenamefileapp::getexepath(void)
{
char
szfilepath[max_path
+
1]={0}
getmodulefilenamea(null,
szfilepath,
max_path)//1111
(strrchr(szfilepath,
'\\')+1)[0]
=
0
//
删除文件名,只获得路径字串
cstring
path
=
szfilepath
return
path
}
void
crenamefileapp::addtotxt(cstring
strtemp)
{
cstring
h_path
h_path=getexepath()
h_path=
h_path+"文件名核对.txt"
cfile
file
if(!file.open(_t(h_path),cfile::modereadwrite|
cfile::typebinary))
{
file.open(_t(h_path),cfile::modecreate|cfile::modereadwrite|
cfile::typebinary)
}
file.seektoend()
file.write(strtemp,strtemp.getlength())
file.close()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)