1

I'm having issue in the ifstream function, I have tried using the argv[1] as parameter but wont load the map, the map is located in the same folder of main code. I'm stucked here and can not debug.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;

int main (int argc, char *argv[]){

    int h;
    int w;
    int var;


    string inputLine;

    ifstream f;
    f.open("map.pgm",ios::in);
    if (!f){
        cout << "error" << endl;
        exit(1);
    }

I'm using Visual Studio 2017

Rama
  • 3,222
  • 2
  • 11
  • 26
  • 1
    Visual Studio can debug. What prevents you from debugging? – Thomas Weller Mar 17 '17 at 14:27
  • 1
    In VS by default program current directory is not where source is, but executable. So either move you `map.pgm` there or specify full path – Slava Mar 17 '17 at 14:28
  • Use Process Monitor to find out where it tries to load the map from – Thomas Weller Mar 17 '17 at 14:28
  • And `ifstream` is not a function – Slava Mar 17 '17 at 14:29
  • 5
    ***In VS by default program current directory is not where source is, but executable.*** This is wrong. In Visual Studio the default folder is the folder containing the project file unless you changed the default. This way if you run a Debug or Release configuration your data files are in the same place. – drescherjm Mar 17 '17 at 14:30
  • Have you tried using the full path of the file, just to rule out the possibility that your application is looking in the wrong place? – Trevor Mar 17 '17 at 14:37

1 Answers1

-1

Change this line:

if (!f){

by this:

if (!f.is_open()){

BTW you can check current directory path with GetModuleFileName

Community
  • 1
  • 1
Rama
  • 3,222
  • 2
  • 11
  • 26