Search
 
SCRIPT & CODE EXAMPLE
 

CPP

input 2d vector c++

vector<vector<int> > d;
int val;
for(int i = 0; i < in; i++){
    vector<int> temp;
    for(int j = 0; j < in; j++){
        cin >> val;
        temp.push_back(val);
    }
    d.push_back(temp);
    temp.clear();
}
From SpyrosD3v25
Comment

input 2d vector c++

vector<vector<int> > d;
int val;
for(int i = 0; i < in; i++){
    vector<int> temp;
    for(int j = 0; j < in; j++){
        cin >> val;
        temp.push_back(val);
    }
    d.push_back(temp);
    temp.clear();
}
Comment

how to take input in 2d vector in c++

std::vector<vector<int>> d;
//std::vector<int> d;
cout<<"Enter the N number of ship and port:"<<endl;
cin>>in;
cout<<"Enter preference etc..:
";
for(i=0; i<in; i++){ 
cout<<"ship"<<i+1<<":"<<' ';
    for(j=0; j<in; j++){
    cin>>temp;
    d[i].push_back(temp); 
    }
}
Comment

how to take input in 2d vector in c++

std::vector<vector<int>> d;
//std::vector<int> d;
cout<<"Enter the N number of ship and port:"<<endl;
cin>>in;
cout<<"Enter preference etc..:
";
for(i=0; i<in; i++){ 
cout<<"ship"<<i+1<<":"<<' ';
    for(j=0; j<in; j++){
    cin>>temp;
    d.push_back(temp);// I don't know how to push_back here!!
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to copy one vector to another 
Cpp :: c++ length of char* 
Cpp :: c++ iterate over vector 
Cpp :: adding elements to a vector c++ 
Cpp :: print float number with only four places after the decimal point in c++ 
Cpp :: c++ find element in vector 
Cpp :: chrono start time in c++ 
Cpp :: factorial in c++ 
Cpp :: c++ hide show console 
Cpp :: c++ constructors 
Cpp :: for loop with array c++ 
Cpp :: matplotlib hide numbers on axis 
Cpp :: c++ string contains 
Cpp :: flags for g++ compiler 
Cpp :: c++ random number within range 
Cpp :: memset in c++ 
Cpp :: how to do sets in cpp 
Cpp :: How to find the suarray with maximum sum using divide and conquer 
Cpp :: c++ tokenize string 
Cpp :: vector reverse function in c++ 
Cpp :: Quicksort taking random pivot 
Cpp :: reverse function in cpp string 
Cpp :: C++ Structures (struct) 
Cpp :: back() in c++ 
Cpp :: palindrome checker in c++ 
Cpp :: reverse level order traversal 
Cpp :: to lowercase c++ 
Cpp :: max in c++ 
Cpp :: stack overflow c++ 
Cpp :: c++ string conversion operator 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =