Redirect both cout and stdout to a string in C++ for Unit Testing

前端 未结 4 1305
一个人的身影
一个人的身影 2020-12-03 02:49

I\'m working on getting some legacy code under unit tests and sometimes the only way to sense an existing program behavior is from the console output.

I see lots of

4条回答
  •  感动是毒
    2020-12-03 03:29

    Try sprintf, that's more efficient.

    int i;
    char str[] = "asdf";
    char output[256];
    sprintf(output, "asdfasdf %s %d\n", str, i);
    

提交回复
热议问题