Ramyad
Ramyad

Reputation: 107

Pass file as an argument to visual studio

I try to debug a program in VS2010. In Windows PowerShell I type./Nbody.exe ./config.txt. But, when I enter .\config.txt or other forms of it in the Command Argument form Debugging section from Property Manager window it seems that my program cannot find the file. In fact this part of my code respond:

ifstream CSVfile(CSVFileName);

if (CSVfile == NULL) {
    cout << "ERROR: Cannot Open CSV file" << endl;
    exit(1);
}

Upvotes: 2

Views: 4931

Answers (1)

Raydel Miranda
Raydel Miranda

Reputation: 14360

Visual studio calcutates relative paths starting at working dir path. So, you have to use visual studio variables as $(ProjectDir) to compound the paths of your files.

Something like: $(ProjectDir)\config.txt, otherwise you have to set the path relative to working dir path.

Let's say your structure is this:

project_name
    + project_name
    | project_name.sln
    | debug
        | project_name.exe
        | config.txt
    + ipch 

and you have .\project_name\project_name as working directory.

The path you enter in the project configuration for debugging has to be relative to the working dir:

..\debug\config.txt

Update

As @Goku states in his (I'm assuming Goku is a 'he', :) ) comment:

For VS2017, $(ProjectDir) already contained a '\' concatenated on the directory name.

Upvotes: 1

Related Questions