CLion C++ can't read/open .txt file in project directory
Clion looks for input files and writes output files to the Debug folder. If you put your input files in there it will see them.
I'm going to presume that the working directory is being set to the path to the executable file instead of your CMakeLists.txt file.
To fix this, EITHER:
- put the .txt next to the executable file
- Explicitly set the working directory for debugging
- Enter the full path to the .txt file as explained in ti7's answer.
if inputFile.is_open()
always returns false
, inputFile.open("twoday.txt");
is not opening the file correctly, presumably because it can't find "twoday.txt"
Try setting an explicit path like "c:/path/twoday.txt"
or "/path/twoday.txt"
if you're using Linux. You could also try writing a file instead to see where it shows up, or something more exotic to return the current path.