#include <iostream>
#include <fstream>
#include <stdlib.h> // includes the "atoi" function
#include <string>
using namespace std;
#include <sstream>;
int main()
{
std::fstream f;
f.open("file.in", std::fstream::in);
// read data
int count = 0;
std::string line = "";
getline( f, line, '\n' );
count = atoi( line.c_str() );
f.close();
f.open("file.in", std::fstream::out | std::fstream::trunc);
// write data
++count;
f << count << endl;
f.close();
return 0;
}
这在Visual Studio中以调试模式工作,但是当我将其作为应用程序运行时,它不起作用。我已经初始化了所有变量,所以我不确定还要检查什么。
答案 0 :(得分:2)
这一行
f.open("file.in", std::fstream::in);
确保file.in位于\ bin \ release
我还建议您使用try / catch语句并打印错误