作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个库提供的函数(因此我无法编辑它的源代码),它会将输出打印到标准输出。我希望在字符串变量中获取该输出,以便我可以检查它的一些条件。做这个的最好方式是什么?如果没有多线程和文件 I/O,我能做到吗?
[编辑] 类似问题(在评论中指出):
使用多线程:
Capture Output of Spawned Process to string
如果您事先知道输出大小:
最佳答案
使用 rdbuf。
std::stringstream stream;
auto * old = std::cout.rdbuf(stream.rdbuf());
CallFunction();
std::cout.rdbuf(old);
std::string value = stream.str();
关于c++ - 如何将输出发送到 stdout 到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33701162/
我是一名优秀的程序员,十分优秀!