Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用文本文件作为二进制文件的输入_C++_Linux_Bash_Redirect_Cat - Fatal编程技术网

C++ 使用文本文件作为二进制文件的输入

C++ 使用文本文件作为二进制文件的输入,c++,linux,bash,redirect,cat,C++,Linux,Bash,Redirect,Cat,我试图测试我的家庭作业(背包问题),每次我重新编译时都会重复输入所有这些输入 以下是我得到的: will@will-mint ~/code/byun-sp15 $ g++ knapsack.cpp will@will-mint ~/code/byun-sp15 $ ./a.out Please enter number of items: 3 Please enter Knapsack Capacity: 10 Enter weights and values of 3 items:

我试图测试我的家庭作业(背包问题),每次我重新编译时都会重复输入所有这些输入

以下是我得到的:

will@will-mint ~/code/byun-sp15 $ g++ knapsack.cpp
will@will-mint ~/code/byun-sp15 $ ./a.out
Please enter number of items: 3
Please enter Knapsack Capacity: 10
Enter weights and values of 3 items: 
    Item 1: 3 40
    Item 2: 2 10
    Item 3: 5 50
0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 
0 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 
0 * 50 * 50 * 99 * 50 * 50 * 60 * 60 * 60 * 60 * 
显然我的桌子不对,请不要帮我。没有破坏者! 我将
3 10 3 40 2 10 5 50
放入test.txt并尝试了以下操作:

will@will-mint ~/code/byun-sp15 $ vim test.txt
will@will-mint ~/code/byun-sp15 $ test.txt > ./a.out
test.txt: command not found
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out >> output.log
will@will-mint ~/code/byun-sp15 $ vim output.log
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out 2> output.log
will@will-mint ~/code/byun-sp15 $ vim output.log
will@will-mint ~/code/byun-sp15 $ ./a.out < test.txt
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out > output.log
will@will-mint ~/code/byun-sp15 $ vim output.log 
will@will-mint ~/code/byun-sp15 $ ./a.out << test.txt
will@will-mint~/code/byun-sp15$vim test.txt
will@will-mint~/code/byun-sp15$test.txt>/a.out
test.txt:未找到命令
will@will-mint~/code/byun-sp15$cat test.txt |/a.out
will@will-mint~/code/byun-sp15$cat test.txt |/a.out>>output.log
will@will-mint~/code/byun-sp15$vim output.log
will@will-mint~/code/byun-sp15$cat test.txt |./a.out 2>output.log
will@will-mint~/code/byun-sp15$vim output.log
will@will-mint~/code/byun-sp15$./a.outoutput.log
will@will-mint~/code/byun-sp15$vim output.log

will@willMUT~/COND/BYUN-SP15 $ ./AUDE <代码> ./AUTHOUT < Test.txt < /Cord>或未优化版本:<代码> CAT Test.txt/.O.Out/<代码>应该工作,如果Test.txt内容是正确的.请看.A:赛勒斯,我是不是都试过了,这是否意味着C++中存在问题?@我希望不要编写脚本,当您执行
test.txt>/a.out
时,搜索并尝试使用一个命令后,您销毁了
a.out
。请重新编译。