Pregunta

#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;
}

This works in debug mode in Visual Studio but when I run it as an application it doesn't work. I've initialized all variables so I'm not sure what else to check.

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top