Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<iostream>
#include<vector>

using namespace std;

int main()
{
   vector< vector< float > > v;
   float x;
   for(int i = 0;i < 3; i++)
   {
      for(int j = 0;j < 3 ; j++)
      {
        cin >> x;
        v.push_back(x);
      }
   }
   
   for(int i = 0;i < 3; i++)
   {
      for(int j = 0;j < 3; j++)
      {
         cout << v[i][j];
      }
   }
   return 0;
}


What I have tried:

i have tried the above code but it shows error:
no matching function for call to 'std::vector<std::vector xmlns:std="#unknown"><int> >::push_back(int&)'
v.push_back(x);
Posted
Updated 18-Jun-16 7:26am
v2

1 solution

You defined a vector of vector with that
C++
vector< vector< float > > v;

so you need to dereference it.

that code should do the job:
C++
v[i].push_back(x);
 
Share this answer
 
Comments
Rahul Thengadi 18-Jun-16 13:31pm    
after applying above solution it shows: Segmentation fault (core dumped)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900