버퍼 스트림을 다른 스트림으로 푸시 한 후 s
문자열 스트림을 다시 사용할 수 있습니까 stream
.rdbuf()
기능이 있습니까?rdbuf 후에 문자열 스트림을 다시 사용
나는 상황 재구성 :
#include <iostream>
using namespace std;
#include <fstream>
#include <sstream>
#include <assert.h>
ofstream f("t.txt");
void dump(stringstream & s){
f << s.rdbuf();
assert(f.good()); // THIS ASSERT FAILS IN my code (see main)
}
void doit1(){
static std::stringstream s;
s.str("");
s.clear();
s.seekp(0);
s.seekg(0);
s << "1";
dump(s);
}
void doit2(){
// your code goes here
std::stringstream s;
s << "2";
dump(s);
}
int main() {
// your code goes here
doit2();
doit1(); // ASSERT FAILS HERE
}
내 프로그램이 충돌하지 않습니다, 그리고 텍스트 파일의 출력이 없다! doit1()을 호출하여 어설 션이 정확하게 실패합니다. 왜 doit2가 스트림 f
을 나쁜 상태로 설정합니까?
무엇이 잘못 되었습니까?
나를 위해 작동합니다. – Oncaphillis
나를 위해, 그러나 어떻게 든 그것은 여기에서하지 않는다, MWE를 얻으려고 노력한다 – Gabriel
"그것은 여기에서"무엇을 의미하지 않느냐? – 0x499602D2