如何指定qt creator从哪里读出数据

时间:2013-09-15 10:32:03

标签: c++ qt qt-creator

我希望qt创建者从std::cin中读取文件中的数据。 那是我想要的东西

cat in.txt type | ./may_executable_file

我需要它来测试qt creator中的程序,每次相同的数据都不要在控制台中收集。

1 个答案:

答案 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 Executablehttp://qt-project.org/doc/qtcreator-2.5/creator-run-settings.html的运行设置中使用QCreator

相关问题