0

qtクリエーターがファイルからデータを読み込んでいるかのようにstd::cin. それは私が何かをしたいです

cat in.txt type | ./may_executable_file

同じデータを毎回コンソールに収集しないように、qtクリエーターでプログラムをテストするために必要です。

4

1 に答える 1

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.
}

別のオプションは、 http://qt-project.org/doc/qtcreator-2.5/creator-run-settings.html の実行設定で使用することCustom Executableです。QCreator

于 2013-09-15T10:38:53.760 に答える