문제

누군가 나를 도울 수 있습니까?

나는 다음과 같은 일을하려고 노력하고 있습니다.

#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
#include <sstream>  
#include <cassert>  

namespace io = boost::iostreams;
typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee;
std::stringstream ss1, ss2;
Tee my_split(ss1, ss2); // redirects to both streams
my_split << "Testing";
assert(ss1.str() == "Testing" && ss1.str() == ss2.str());

그러나 VC9에서는 컴파일하지 않습니다.

c:\lib\boost_current_version\boost\iostreams\stream.hpp(131) : error C2665: 'boost::iostreams::tee_device<Sink1,Sink2>::tee_device' : none of the 2 overloads could convert all the argument types

누구든지 이것을 일에 얻은 사람이 있습니까? 나는 내 자신의 수업을 할 수 있다는 것을 알고 있지만 내가 무엇을 잘못하고 있는지 알고 싶습니다.

감사

도움이 되었습니까?

해결책

당신은 사용합니다 생성자 포워드 버전io::stream, 이것은 티 스트림 자체를 구성하고 모든 논증을 전달합니다. C ++ 03은 인수를 함수로 전달할 때만 제한된 기능을 가지고 있습니다 (기하 급수적으로 쉽게 성장하는 과부하의 양). 그것 (io::stream) 다음과 같은 제한을합니다.

이들 각 멤버는 스트림 인스턴스를 구성하고 주어진 인수 목록에서 구성된 장치의 인스턴스와 연결합니다. 관련된 T 생성자는 가치 또는 const 참조별로 모든 인수를 취해야합니다.

글쎄요,하지만 tee_device 생성자가 말합니다

주어진 싱크 쌍을 기반으로 tee_device 인스턴스를 구성합니다. 해당 템플릿 인수가 스트림 또는 스트림 버퍼 유형 인 경우 각 함수 매개 변수는 정식 참조입니다.

물론 그것은 작동하지 않을 것입니다. io::stream a를 취하는 다른 생성자를 제공합니다 T 첫 번째 논쟁으로. 이것은 여기서 작동합니다 (적어도 컴파일됩니다. 어설 션은 실패합니다. boost::iostreams 그래서 나는 그것을 도울 수 없다)

namespace io = boost::iostreams;
typedef io::tee_device<std::stringstream, std::stringstream> TeeDevice;
typedef io::stream< TeeDevice > TeeStream;
std::stringstream ss1, ss2;
TeeDevice my_tee(ss1, ss2); 
TeeStream my_split(my_tee);
my_split << "Testing";
assert(ss1.str() == "Testing" && ss1.str() == ss2.str());

편집 : 전화 후 flush() 또는 스트리밍 << std::flush, 주장은 통과합니다.

다른 팁

아마도 다음과 같이 설정해야 할 것입니다.

typedef io::tee_device<std::stringstream, std::stringstream> Tee;
typedef io::stream<Tee> TeeStream;

std::stringstream ss1, ss2;
Tee my_tee(ss1, ss2);
TeeStream my_split(my_tee);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top