Originally Posted by
Veneficvs
I could create a vector of CBox classes.. and whenever a new series of numbers is entered, to resize the vector so that it could contain as many objects as entered.. but if I declare it as static, then I could not make it have another dimension.. and if I make it dynamically and then readjust its dimension, would not I lose the data so far?
As you stated, each object as a vector. This does not conflict with the idea of having a vector of these objects:
Code:
#include <istream>
#include <vector>
#include <string>
#include <sstream>
class Box
{
public:
// ...
friend std::istream& operator>>(std::istream& in, Box& box);
private:
std::vector<int> numbers;
};
int main()
{
std::vector<Box> boxes;
// ...
return 0;
}
std::istream& operator>>(std::istream& in, Box& box)
{
// Read a line from in into a std::string.
// Initialise a std::stringstream with that std::string.
// Extract from the std::stringstream into box.numbers.
// ...
return in;
}