I have a .txt file in my project directory that I made and populated with data.
directory structure looks like:
/Users/asd/ClionProjects/ProjectWithT
I found out how to set CMake to build in your project directory in CLion.
I just set mine to ".\build" and now it always builds into my project including the file you make.
I had the same issue:
Do : Ctrl + Alt + F12 to get the full file path
inputFile.open()
Happy Coding
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.
The other answers identify the issue, which really has nothing to do with CLion. When any executable starts up, it has a current working directory. By default, that is the directory where the executable lives. If the file you want to read lives anywhere else, you have to do one of three things:
I've created a brief tutorial video on how to accomplish the last: https://youtu.be/dTtZEAfh_LM
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:
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.