user2424001
user2424001

Reputation:

unhandled exception at xxxxx unable to write at location. It doesn't execute beyond the getline....... in visual studio 2010

  #include "StdAfx.h"


   int main(int argc, char **argv) 
    {
  // using namespace std;
  string line;
  cout<<"dsadasdas";
  fstream file  ("D:\source_details.txt", ios::in);
  cout<<"dsadasdas"<<endl;

  if (file.is_open())
   {    cout<<"dsadasdas";
        getline (file,line);
     cout<<"dsadasdas";
    cout<<line;
    }
  else
   {
    cout<<"Not possible"<<endl;

   }




    return (0);
   }

the code doesnt get executed beyond the getline...... I get the unhandled exception error. I dont understand what is wrong with my code. It is really simple. Actually this is a very small part of a big code i am trying to run in visual studio but i keep getting this error.

Upvotes: 0

Views: 133

Answers (1)

catscradle
catscradle

Reputation: 1719

fstream file  ("D:\source_details.txt", ios::in);

You need to escape '\' symbol here, like this:

fstream file  ("D:\\source_details.txt", ios::in);

Upvotes: 3

Related Questions