I am new to c++, and one day during codchef contest we were given an input which we have to store in vector and do something.The input was like this
123
Now I'm currently working on it to understand the basics and working of vector like i have learned the arrays in C lang & python.Here's what I have implemented;
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v1;
string x;
getline(cin,x); //takes input as string
stringstream s(x);
int temp;
for(int i=0;i<x.size();i++)
{
char j=x[i]; //Iterating over each n every string
int num;
stringstream ss;
ss<<j;
ss>>num; //covert the string to integer
v1.push_back(num);
}
for(auto i=v1.begin();i!=v1.end();++i) //output
cout<<*i<<" ";
return 0;
}
After runnung this i will get output of vector like this:
1 2 3
So my question is,Is there any easy way to implement this like in python we use .split() .