开发者

How do I assign vector of vectors of strings using pointers to multiple vectors in C++?

I need help figuring out bits of code. I am not sure how to populate vector> using pointers to multiple vectors of strings.

Please make suggestions only on lines that contain //HELP NEEDED HERE

#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<string>* pointerReturner (string str1, string str2, string str3)
{
    vector<string> *vList = new vector<string>();
    vList->push开发者_开发百科_back(str1); 
    vList->push_back(str2);
        vList->push_back(str3); 
    return vList;
}

int main(int argc, char* argv[]) {

    vector<string> *vMakeList1;
        vMakeList1 = pointerReturner ("1","8-20-2011","Ford");

        vector<string> *vMakeList2;
    vMakeList2 = pointerReturner ("2","8-20-2011","Honda");

        vector<string> *vMakeList3;
        vMakeList3 = pointerReturner ("3","8-20-2011","Toyota");

        vector<vector<string>> *MakeList;

        //HELP NEEDED HERE

delete vMakeList1, vMakeList2, vMakeList3;


    vector<vector<string> >::iterator i = MakeList->begin();
    for( ; i != MakeList->end(); ++i)
    {
        vector<string>::iterator pos = (*i).begin();
        for ( ; pos!=(*i).end(); ++pos)
            cout << *pos << endl;
    }

    cin.get();
    return 0;
}

The results is the vector<vector<string>> populated with relevant data.


MakeList = new vector<vector<string> > ();

MakeList->push_back(*vMakeList1);
MakeList->push_back(*vMakeList2);
MakeList->push_back(*vMakeList3);


You cannot. You would need a vector<vector<string>*>* MakeList. And, holy too many pointers and new Batman.


Well

vector<vector<string>> *MakeList = new vector<vector<string>>();
MakeList->push_back(*vMakeList1);
MakeList->push_back(*vMakeList2);
MakeList->push_back(*vMakeList3);

would seem to do the job.

This is not the way to do things, but you seem to be aware of that already.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜