Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ - CLion : What should I do to use input text file?

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.

picture

But it does not works.

like image 440
newbie16 Avatar asked Mar 15 '17 15:03

newbie16


People also ask

How do I use text files in CLion?

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.

How do you search in CLion?

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.


2 Answers

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): enter image description here

Now there is an option: "Redirect input from". Just click the folder and find your input file. enter image description here

like image 122
Miguel Duran Diaz Avatar answered Sep 20 '22 08:09

Miguel Duran Diaz


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

like image 28
Vishal Singh Avatar answered Sep 19 '22 08:09

Vishal Singh