문자열로 :: istream로를 문자열로 :는 표준 데이터의 고정 길이를 복사 :: istream로를 내가 표준 데이터의 고정 된 길이를 복사 할
std::istream & operator >> (std::istream & is, LogMsg & msg)
{
// read in 4 bytes - a uint32_t that describes the number of bytes in message:
// next, read the message bytes into the LogMsg
typedef std::istream_iterator<unsigned char> Iter;
Iter i (is);
uint32_t nSize = 0;
std::string & sMsg = msg.MsgRef();
is >> nSize;
sMsg.reserve(nSize);
std::copy(
i.begin(), i.begin() + nSize,
std::back_inserter(sMsg)
);
return is;
}
난 못해 iterator의 std :: istream_iterator :: begin() 함수는 C++ 11에서만 사용할 수 있습니다 (gcc를 사용하여 -std = gnu ++ 0x로 제한됨). 4.4.7
고정 된 길이의 데이터를 입력 스트림에서 문자열로 복사 할 수 있습니까?
원래 std :: istream :: read에서 loooked되었습니다. llowing 구문
is.read (buffer,length);
하지만 난 당신이 문자열의 내부 버퍼로 읽을 수있는 내가 임시 버퍼에 복사를하지 않으려는 생각하지 않습니다. 어떻게 든 streambuf를 사용할 수 있습니까?
AFAIK C++ 11에서'istream_iterator'를위한'begin()'/'end()'함수는 없습니다. – 0x499602D2
스트림은 컨테이너가 아닌 _ 데이터 _ 흐름입니다. –