0$房天下问答|C++文件输出输入流问题(不在默认路径下)$https://m.fang.com/ask/ask_1734378.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=1734378
-
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;}这段代码就改了一下打开文件路径就打不开,为什么?请高手指点!
更多
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功