标题:关于文件读写
只看楼主
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
帖 子:605
专家分:2489
注 册: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-316411-1-1.html




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

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