Continuando con le variabili di CMakeLists CMAKE_RUNTIME_OUTPUT_DIRECTORY
, faccio quanto segue. Nella directory principale del mio progetto, creo una directory, ad esempio out
.Poi, nel mio CMakeLists.txt
ho impostato la CMAKE_RUNTIME_OUTPUT_DIRECTORY
a quella directory:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out)
nota, che deve venire prima di avere
add_executable(YourProject ${SOURCE_FILES})
Potrei anche aggiungere che invece di utilizzare fopen()
vorrei tenere più oggetti -orientato utilizzando std::ifstream
:
std::ifstream inFile("data.txt");
// check if it opened without issue...
if (!inFile) {
processError(); // a user-defined function to deal with the issue
} else {
// All is good, carry on...
// and when you're done don't forget
inFile.close();
}
fonte
2017-05-07 22:18:02
Questo ha funzionato per me. Grazie – pyetti