Answers for "how to input value in vector in cpp"

C++
0

taking user input for a vector in c++

vector<int> g1;
for(i=0;i<n;i++)
{
  cin>>a;
  g1.push_back(a);
}
Posted by: Guest on June-11-2021
0

get vector input from string in c++

vector<int> getVectorInput(string s){
    string res="";
    vector<int> arr;
    for(auto e : s){
        if(e==' '){
            if(res.size()!=0)
            arr.push_back(stoi(res));
            res="";
            continue;
        }
        res+=e;
    }
    if(res.size()!=0)
        arr.push_back(stoi(res));
    return arr;
}
Posted by: Guest on September-23-2021

Code answers related to "how to input value in vector in cpp"

Browse Popular Code Answers by Language