0
std::cout
에 대한 버퍼링을 사용하지 않도록 설정하는이 프로그램이 있습니다. 내가 출력 장치에 쓴 것을 인쇄하고 싶지만, 내가 인쇄 할 때 str
은 나오지 않습니다.버퍼링되지 않은 I/O가 작동하지 않습니다.
#include <iostream>
#include <sstream>
#include <string>
int main()
{
std::cout.rdbuf()->pubsetbuf(0, 0);
std::cout.unsetf(std::ios::unitbuf);
std::cout << "Hello, World\n";
std::stringstream ss;
ss << std::cout.rdbuf();
std::string str{ss.str()};
std::cout << str; // nothing
// str.size() == 0
}