Where to put file in Microsoft Visual Studio so that it will find them automatically?

StackOverflow https://stackoverflow.com/questions/23566461

  •  19-07-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top