简体   繁体   中英

Strange (c++) debug issues using VS2013

I have inherited a project to work on and the initial build was developed on linux. I dont know if this matters or not but thought I would share it.

In order to debug the project on a windows machine I first use the CMakeGUI on win7 to create a Visual Studio Solutions file to open the project using Visual Studio 2013 and then set the startup project and build the project I am interested in. Up till now everything is okay. Now comes the confusing part.

On load the program is suppose to read a file lets call it in.dat and is declared in const char * inputFileName this variable is then passed through a class which attempts to open then file to obtain data.

fstream fs;
fs.open(inputFileName.c_str(), fstream::in);
    if(!fs.is_open())
    {
        std::cout << "Cannot open input file!" << std::endl;
        exit(0);
    }

This where I am stumped...the file when placed in the debug folder for some reason cannot be opened ie fs.is_open() returns false when I try debugging the application BUT if I cd directly into the debug folder of the project, outside of VS, and run the executable it runs as expected ie fs.is_open() now returns true .

Your debugger's working directory defaults to your project's root directory and the binary is in the \\debug subdirectory, resulting, in effect, to the path to the input file being wrong.

Set the debugger's working directory to \\debug. Here is more info on that: https://msdn.microsoft.com/en-us/library/kcw4dzyf(v=vs.120).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM