I want to read .txt file in my C/C++ project in CLion IDE.
I want to automate the command that I run in bash:
./<executable_file> < input.txt
I edited program parameter in Run/Debug configuration.
But it does not works.
To let CLion open a text file: You must place the file in the “cmake-build-debug” folder inside your CLion project's folder. There are two ways to accomplish this: From within CLion, in the left-hand panel area, expand the drop-downs until you see the “cmake-build-debug” folder.
From the main menu, select Edit | Find | Find in Files Ctrl+Shift+F . In the search field, type your search string. Alternatively, in the editor, highlight the string you want to find and press Ctrl+Shift+F . CLion places the highlighted string into the search field.
If someone is still interested in this, at the current date, CLion has added this feature. Go Edit Configurations (top right corner toolbar, name of your project | Debug):
Now there is an option: "Redirect input from". Just click the folder and find your input file.
It is not officially supported as of now, you can do the following.
If your input file is input.txt, you can use freopen to set stdin file as input.txt
freopen("input.txt","r",stdin);
if you want to do the same with your output:
freopen("output.txt","w",stdout);
this will work for std::cin (if using c++), printf, etc...
This will help you in debugging your code in clion
Similar Question CLion standard input while debugging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With