一个关于文件读写的问题,请高手指教

duzhenguo 2002-07-12 06:36:21
一段代码
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main ()
{
ifstream infile("d:\\temp\\infile.txt");
if (!infile)
{
cerr <<"can not open the file"<<endl;
return -1;
}
ofstream outfile("d:\\temp\\outfile.txt");
if (!outfile)
{
cerr <<"can not output the file"<<endl;
return -2;
}
string word;
vector <string> tree;
while (infile>>word)
{
tree.push_back(word);
}
cout <<"unsorted text"<<endl;
for (int ix = 0; ix < tree.size(); ++ix)
{
cout << tree[ix]<<' ';
}
cout << endl;
sort ( tree.begin(), tree.end() );

outfile <<"sorted text\n";
for ( ix = 0; ix < tree.size(); ++ix)
{
outfile << tree[ix]<< ' ';
}
outfile <<endl;
return 0;
}
为什么只能在编译的目录下运行,换个目录就不行了
...全文
49 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leasun 2002-07-22
  • 打赏
  • 举报
回复
因为找不到infile
duzhenguo 2002-07-22
  • 打赏
  • 举报
回复
参数在哪里修改?/
81739649 2002-07-17
  • 打赏
  • 举报
回复
注意看一下路径,你的编译环境参数
duzhenguo 2002-07-14
  • 打赏
  • 举报
回复
一换到别的目录下,就提示can not open the file
但是在编译成的那个目录下就可以
LeeMaRS 2002-07-12
  • 打赏
  • 举报
回复
提示出什么错误??

70,036

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧