0
#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 中的调试模式下工作,但是当我将它作为应用程序运行时它不起作用。我已经初始化了所有变量,所以我不确定还要检查什么。

4

1 回答 1

2

This line

 f.open("file.in", std::fstream::in);

Make sure file.in is in \bin\release

I also advice your to use try/catch statements and print your errors

于 2013-05-13T01:55:34.993 回答