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
。请重新编译。