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

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

  •  19-07-2023
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top