注册 登录
编程论坛 C++教室

我的第一个C++程序

fydgo 发布于 2009-12-18 09:46, 839 次点击
#include <fstream>
这是我写的第一个程序,很简单,但我不明白为什么从文件读不了数据,然后传送的文件out.dat呢?我是菜鸟~~~
int main()
{
    using namespace std;
    ifstream in_stream;
    ofstream out_stream;

    in_stream.open("D:\我的文档\桌面\in.dat");
    out_stream.open("D:\我的文档\桌面\out.dat");

    int first,second,third;
    in_stream>>first>>second>>third;
    out_stream<<"the sum of the first 3\n"
              <<"numbers in in.dat\n"
              <<"is"<<(first+second+third)
              <<endl;
    in_stream.close();
    out_stream.close();

    return 0;
}
我in.dat文件里的数字是
1
2
3
5 回复
#2
debroa7232009-12-18 11:27
in_stream.open("D:\\我的文档\\桌面\\in.dat");
out_stream.open("D:\\我的文档\\桌面\\out.dat");
'\'是转义符,文件路径中使用时注意。
还可以写成

in_stream.open("D:/我的文档/桌面/in.dat");
#3
生活无意义2009-12-21 20:35
我什么时候才能自己写程序啊
#4
flyingcloude2009-12-22 00:00
回复 3楼 生活无意义
现在就可以开始了
#5
lyl66504212009-12-22 17:18
努力学习中
#6
lklqlk19912010-02-21 10:24
好好搞。这东西只能一点一点来的
1