Мне нужно создать std :: string с первыми N байтами istream ... Как мне это сделать?
std::istream istm;
std::string str;
istm >> str; //will read tons of stuff until finds whitespace
std::string str(N, ' ');
istm.read(str.data(), N); //can't write into buffer inside string, cause data() returns const char*
std::unique_ptr<char[N+1]> buf;
istm.read(buf.get(), N);
std::string str(buf.get()); //should work, but why extra buffer?
итак ... как мне это сделать правильно?