CLion standard input while debugging

后端 未结 4 1198
[愿得一人]
[愿得一人] 2021-02-03 23:41

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.

<
4条回答
  •  迷失自我
    2021-02-03 23:55

    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.

提交回复
热议问题