| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8505 人关注过本帖
标题:请教在VC里向TXT文件写数据
取消只看楼主 加入收藏
jzz514
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-21
收藏
 问题点数:0 回复次数:2 
请教在VC里向TXT文件写数据
在VC++里,一个变量已赋值,想在这个赋值语句之后将这个变量的值写到规定路径的相应
的TXT文件里,要求是这个变量不停被赋予新的值,然后这个值就依次写到到TXT文件里,
并且上次的值不能被这次的值覆盖。
由于急用
恳请达人帮忙写个程序段,谢谢
搜索更多相关主题的帖子: TXT文件 数据 变量 赋值 
2008-03-21 21:56
jzz514
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-21
收藏
得分:0 
我把程序嵌入后,有编译错误.
于是将代码改为:
FILE file;
file=fopen("c:\\test.txt","r");
if  ( file == NULL )
{
   //没有创建文件,则创建文件
    file=fopen("c:\test.txt","w");
   //写入数据
     file.write (strtemp);
   fclose(file);
}
else
{
    //表示创建了,则关闭后,在用追加方式写入
    fclose(file);
   file=fopen("c:\test.txt","a");
   //写入数据
    file.write (strtemp);
   fclose(file);
}

发现还有编译错误
错误如下:
--------------------Configuration: CommWizard - Win32 Debug--------------------
Compiling...
CommWizardDlg.cpp
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(294) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(295) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'struct _iobuf' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(298) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(300) : error C2039: 'write' : is not a member of '_iobuf'
        d:\microsoft visual studio\vc98\include\mbstring.h(92) : see declaration of '_iobuf'
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(301) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(306) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(307) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(309) : error C2039: 'write' : is not a member of '_iobuf'
        d:\microsoft visual studio\vc98\include\mbstring.h(92) : see declaration of '_iobuf'
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(310) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.

CommWizard.exe - 1 error(s), 0 warning(s)


敬请修改
2008-03-25 17:18
jzz514
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-21
收藏
得分:0 
回复 2# 的帖子
我把程序嵌入后,有编译错误.
于是将代码改为:
FILE file;
file=fopen("c:\\test.txt","r");
if  ( file == NULL )
{
   //没有创建文件,则创建文件
    file=fopen("c:\test.txt","w");
   //写入数据
     file.write (strtemp);
   fclose(file);
}
else
{
    //表示创建了,则关闭后,在用追加方式写入
    fclose(file);
   file=fopen("c:\test.txt","a");
   //写入数据
    file.write (strtemp);
   fclose(file);
}

发现还有编译错误
错误如下:
--------------------Configuration: CommWizard - Win32 Debug--------------------
Compiling...
CommWizardDlg.cpp
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(294) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(295) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'struct _iobuf' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(298) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(300) : error C2039: 'write' : is not a member of '_iobuf'
        d:\microsoft visual studio\vc98\include\mbstring.h(92) : see declaration of '_iobuf'
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(301) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(306) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(307) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct _iobuf *' (or there is no acceptable conversion)
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(309) : error C2039: 'write' : is not a member of '_iobuf'
        d:\microsoft visual studio\vc98\include\mbstring.h(92) : see declaration of '_iobuf'
E:\激光器驱动\温控电路相关资料\串口精灵源代码\CommWizardDlg.cpp(310) : error C2664: 'fclose' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.

CommWizard.exe - 1 error(s), 0 warning(s)


敬请修改
2008-03-25 17:18
快速回复:请教在VC里向TXT文件写数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026621 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved