| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 541 人关注过本帖
标题:关于文件读写
只看楼主 加入收藏
xishui777
Rank: 2
等 级:论坛游民
帖 子:53
专家分:94
注 册:2010-8-17
结帖率:100%
收藏
已结贴  问题点数:2 回复次数:3 
关于文件读写
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ifstream file2("D:/test.txt");
    if(!file2)
    {
      cout<<"未打开读入文件!!!"<<endl;
      system("pause");
      return 0;
    }
    ofstream file3("D:/test2.txt");
    if(!file3)
    {
      cout<<"未打开写入文件!!!"<<endl;
      system("pause");
      return 0;
    }
    char a;
    while(file2.get(a))
      file3.put(a);
    file2.close();
    file3.close();
    system("pause");
    return 0;
}
代码为什么提示(未打开读入文件!!!)D:/test.txt文件已有
搜索更多相关主题的帖子: 文件 
2010-08-21 16:49
lintaoyn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:606
专家分:2499
注 册:2009-4-8
收藏
得分:1 
"D:/test.txt"改成"D:\\test.txt"试下

迭代的是人,递归的是神。
2010-08-21 17:24
xishui777
Rank: 2
等 级:论坛游民
帖 子:53
专家分:94
注 册:2010-8-17
收藏
得分:0 
改了,还是不行
2010-08-21 17:45
towhee
Rank: 2
来 自:石家庄火车站
等 级:论坛游民
威 望:1
帖 子:48
专家分:69
注 册:2010-8-8
收藏
得分:1 
程序代码:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ifstream file2("D:\\test.txt");
    if(!file2)
    {
        cout<<"未打开读入文件!!!"<<endl;
        system("pause");
        return 0;
    } 
    ofstream file3("D:\\test2.txt");
    if(!file3)
    {
        cout<<"未打开写入文件!!!"<<endl;
        system("pause");
        return 0;
    } 
    char a;
    while(file2.get(a))
        file3.put(a);
    file2.close();
    file3.close();
    system("pause");
    return 0;
}

以上代码编译通过,执行通过,环境vs2005+xp

最穷无非讨饭,不死终会出头
2010-08-21 18:39
快速回复:关于文件读写
数据加载中...
 
   



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

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