房天下 > 房天下问答 > 业主生活 > 其他
  • C++文件输出输入流问题(不在默认路径下)

    #include <fstream>#include <iostream>using namespace std;int main(){ int a[10]; ofstream outfile("1.txt",ios::out); if(! outfile) { cout << "open error!" << endl; exit(1); } for(int i = 0;i < 10;i++) { cin >> a[i]; outfile << a[i] << " "; } outfile.close(); return 0;}以上这段代码可以运行,并在默认路径下可以将数组中的内容输入文件中。#include <fstream>#include <iostream>using namespace std;int main(){ int a[10]; ofstream outfile("d:\1.txt",ios::out); if(! outfile) { cout << "open error!" << endl; exit(1); } for(int i = 0;i < 10;i++) { cin >> a[i]; outfile << a[i] << " "; } outfile.close(); return 0;}这段代码就改了一下打开文件路径就打不开,为什么?请高手指点!

    提问者:昵 称

    发布于2011-01-11

共1个回答
  • Accettind 丨Lv 0
    C语言的转义字符问题,把ofstream outfile("d:\1.txt",ios::out); 改成ofstream outfile("d:\\1.txt",ios::out);就可以了
    +1 2011-01-11 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。