我希望qt创建者从std::cin
中读取文件中的数据。
那是我想要的东西
cat in.txt type | ./may_executable_file
我需要它来测试qt creator中的程序,每次相同的数据都不要在控制台中收集。
答案 0 :(得分:0)
您应该考虑将您的计划重组为可测试的方法,这些方法将从istream
直接从cin
读取。例如:
int do_work(std::istream& is, std::ostream& os)
{
int n, k;
is >> n >> k;
os << n << std::endl << k << std::endl;
}
int main()
{
do_work(std::cin, std::cout);
return 0;
}
现在你可能有你的测试单位:
int test_work()
{
std::ifstream inf("test.txt");
std::stringstream out;
do_work(inf, out);
// Check out for results here.
}
另一种选择就是在Custom Executable
:http://qt-project.org/doc/qtcreator-2.5/creator-run-settings.html的运行设置中使用QCreator
。