一个关于文件读写的问题,请高手指教
一段代码
#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;
}
为什么只能在编译的目录下运行,换个目录就不行了