#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
    string a;
    vector<string> b;
    vector< vector<string> > s;
    while(cin>>a)  {
        b.push_back(a);
        s.push_back(b);

        cout<<s.size()<<endl;//A1
        cout<<s[s.size()-1]<<endl;//A2
    }

    return 0;
}

Any problems with this? If line A2 is deleleted,the program can run.So I think s does exist,but when I add line A2 hoping to see the last element of vector of s ,Cannot run! My IDE:codeblocks(svn build rev 4977 (2008-03-29 18:01:31) gcc 4.2.1 Windows/unicode)
Somebody give a hand? Thanks.

That will not work because the elements in 's' are vector<string> vectors themselves,
ostream operator << has no support for that kind of thing by default.
If you really want to pass e.g. a vector<string> to cout, you can write;

ostream & operator <<(ostream & o, const vector<string> & v)
{
	for(vector<string>::const_iterator it = v.begin(); it != v.end(); ++ it)
	{
		o << *it;
	}

	return o;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.