std::vector<std::stringstream> does not work?

Just lost 1+ hour nailing down my problem to:

1
2
3
4
5
6
7
8
#include <iostream>
#include<vector>
#include<sstream>
int main()
{ std::vector<std::stringstream> X;
  X.resize(10);//comment out this line and it will compile
  return 0;
}

This does not compile (gcc latest version, Ubuntu, default code::blocks project settings). Can anyone explain why? Help appreciated!
tition
P.S. This problem really ticked me off: I am really annoyed for losing my time with this!
Last edited on
In C++03 the elements stored in the vector must be copyable. I don't think std::stringstream is copyable so that could be it.

In C++11 it's enough if the elements in the vector are movable. std::stringstream is movable so it should work for sure. Not sure how up to date GCC is on this though.
Because streams don't have copy constructor (it is private)
A vector requires it's type to be assignable. std::stringstream is not assignable.
I moved away from using std::stringstream so that fixed my problem: thanks for the explanation!

I want to complain that gcc's error message was completely insane, like 1 screen long, and it didn't indicate that X.resize(10) caused the problem. As I had made a bunch of other small changes, it took me forever to locate the exact cause of the problem (had to comment out each piece of new code till I found the real cause of the problem).
Last edited on
Yep, templates errors can be hard to read. Especially when is not your code the one that produce it.
$ g++ tition.cpp 2>&1 | grep error
ios_base.h error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private

If you use push_back
error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
Topic archived. No new replies allowed.