Getting input from external files?

后端 未结 4 2006
我在风中等你
我在风中等你 2021-01-28 11:36

I need to get very basic input from an external file in C++. I tried searching the internet a few times but nothing really applied to what I need. This would be a .txt file that

4条回答
  •  再見小時候
    2021-01-28 11:53

    Aside from the other suggestions, you can simply redirect a file to standard input, like so (where $ is the command prompt):

    $ myprogram < mytextfile.txt
    

    That will run myprogram just as normal but take input from mytextfile.txt as if you had typed it in. No need to adjust your own program at all.

    (This works on both Unix/Linux systems and on Windows.)

提交回复
热议问题