What I'm trying to do is basically:
./myProgram < myData.txt
While I'm debugging with CLion IDE. I just can't find the option to do so.
A similar question - but product-specific to MSVS
For debug press Shift+F9 . To help you inspect the state of your code during debugging, CLion equips you with many useful shortcuts like Step over/into ( F8/F7 ), Step out ( Shift+F8 ), or Run to cursor ( Alt+F9 ).
CLion supports debugging C/C++ executables with GDB (either bundled or custom) on all platforms and with the bundled LLDB on macOS and Linux. Also, there is an LLDB-based debugger for the MSVC toolchain on Windows.
Set line breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 . While in disassembly view, you can set breakpoints the same way you do in the source code.
For newer versions: Go to File --> Settings --> Build, Execution, Deployment --> CMake. Now click the "+" symbol, this should automatically add a Release profile (and, if you press "+" again, a Release with Debug Information profile).
I had the same problem and it seems that CLion is not handling standard inputs yet.
I got around this problem by changing the input stream before running my program.
As an example if you want to input a file stream inside your stdin you can write in your main:
std::ifstream in("ABSOLUTE_PATH_TO_YOUR_FILE");
std::cin.rdbuf(in.rdbuf());
Then you can find a way to toggle this stream change when you want. Note that for files you will need to provide absolute path since the application is run from a different directory than the current one.
I hope this can help until CLion provides a real solution.
Assuming your input file is myData.txt
, you can reopen/reuse the stdin
stream using freopen
freopen("myData.txt","r",stdin);
if you want to do the same with your output:
freopen("myOutput.txt","w",stdout);
this will work for std::cin, printf, etc...
You can find more information about this here: http://www.cplusplus.com/reference/cstdio/freopen/
By the way, there is already a feature request for this. If you are interested, you can vote here so it gets prioritized: https://youtrack.jetbrains.com/issue/CPP-3153
As of CLion 2020.1 this feature is built in:
Input redirection
If you need to redirect input from a file to the stdin of your application, you can now do that. Use a new field in the configuration called Redirect input from. Enter:
- A relative path (CLion will prepend with the Working directory path).
- An absolute path (will be remapped for remote configurations).
- Or macros (like FilePrompt).
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