Getting integer value from string

#include <bits/stdc++.h> using namespace std; vector<int> getValuesfromstring(string s){ stringstream ss; //storing value into stream ss<<s; string temp; int val; vector<int>v; while(!ss.eof()){ /* extracting word by word from stream */ ss>>temp; /* Checking the given word is integer or not */ if(stringstream(temp)>>val){ v.push_back(val); cout<<val<<endl; } /* To save from space at the end of string */ temp=""; } return v; } int main() { int n,r,i=0,j=0,k=0,t,max=0,result=1,x; std::vector<int>vect ; string str; while(getline(cin,str)) { vect=getValuesfromstring(str); } return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.