Question

I've written a program at home on Linux and I have some files that are read in automatically. They are in the same directory as the main.cpp file and when I compile and run using
g++ -Wall main.cpp && ./a.out
the program finds the files, reads them in and works, using this function:

std::vector<std::string> returnFile(std::string filename) {
    std::ifstream infile;
    std::vector<std::string> contents;
    infile.open(filename.c_str());
    for (std::string line; std::getline(infile, line); ) {
        contents.push_back(line);
    }
    infile.close();
    return contents;
}

On Windows, using Microsoft Visual Studio 2010, where do I put the file so that I can run: returnFile("myFile.txt"); and it will find the file?

Was it helpful?

Solution

During normal compilation: - the root directory is your Project direcoty. (where your Project.vcxproj file is)

After Release: - the root directory will be the one of your executeable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top