我每次运行程序时都是文件打开失败,请问问题出在哪了?
文件应如何设置才能打开,我使用的是Microsoft visual Studio 2005
下面使程序:
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
fstream inOut("copyOut",
fstream::ate | fstream::in | fstream::out);
if(!inOut){
cerr << "Unable to open file !" << endl;
return EXIT_FAILURE;
}
ifstream::pos_type end_mark = inOut.tellg();
inOut.seekg(0, fstream::beg);
int cnt = 0;
string line;
system("pause");
while (inOut && inOut.tellg() != end_mark && getline(inOut, line))
{
cnt += line.size() + 1;
ifstream::pos_type mark = inOut.tellg();
inOut.seekp(0, fstream::end);
inOut << cnt;
if (mark != end_mark) inOut << " ";
inOut.seekg(mark);
}
inOut.clear();
inOut.seekg(0, fstream::end);
inOut << "/n" ;
system("pause");
return 0;
}