lundi 25 octobre 2021

How to get integers until \n for n number of lines

My input : the first input is number of lines the input will contain

5
7 3 29 0
3 4 3 
2 3 4 55 5
2 3
1 2 33 4 5

My issue is how can I store them in vector of vector..?

My concept..

.
.
.
cin>>n;
vector<vector<int>>vec;
while(n--)
{
    vector<int>vec2;
    for(**Getting input until the line**){
    vec2.emplace_back(input);}
    vec.emplace_back(vec2)
}

I need to implement that getting input till the line. For this I thought of getting the input as string and storing the values in vector vec2 using strtok after converting it to c_string... But I need to know whether there is any efficient way I can overcome this problem..

Aucun commentaire:

Enregistrer un commentaire