I'm trying to familiarize myself with std streams :). And I whant to initialize vector from stream, using std::istreambuf_iterator. Consider we have some stream:
std::string str("Bla-bla bla-bla-bla");
std::stringstream str_s(str);
When I try to initialize vector like this:
std::vector<char> vec(std::istreambuf_iterator<char>(str_s), std::istreambuf_iterator<char>());
VC compiler doesn't treat vec
as an object of class std::vector<char>
. So if I write:
vec.size()
I`ll get compilation error. Something like: "Expression to the left of .size must be an object of class/struct etc. But if I add extra parentheses around first parameter to vector initialization. Like this:
std::vector<char> vec1((std::istreambuf_iterator<char>(str_s)), std::istreambuf_iterator<char>());
Everything goes OK. Why? What the difference?