简体   繁体   中英

How to specify qt creator from where to read out data

I want that qt creator read out data from the file as though they from std::cin . That is I want something the

cat in.txt type | ./may_executable_file

I need it for testing of programs in qt creator not to collect in the console each time the same data.

You should think about restructuring your program into the testable methods that will read from istream instead directly from cin . For example:

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

And now you may have your test unit like:

int test_work()
{
    std::ifstream inf("test.txt");
    std::stringstream out;
    do_work(inf, out);

    // Check out for results here.
}

Another option is just to use Custom Executable in the run settings of the QCreator : http://qt-project.org/doc/qtcreator-2.5/creator-run-settings.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM