I got this simple program read in a string like "13 11 9 10". I wanna split string then sort them. however the sort() seems not working, any help? input: 13 11 9 10 , output: 13 11 9 10 Thanks!
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> split(string s)
{
istringstream iss(s);
vector<int> result;
do{
string sub;
iss>>sub;
if(sub!="")
result.push_back((int)atoi(sub.c_str()));
}while(iss);
return result;
}
int main(void)
{
string s;
while(cin>>s)
{
vector<int> vec;
vec=split(s);
sort(vec.begin(), vec.end());
for (int i = 0; i < vec.size(); ++i)
{
cout<<vec[i]<<endl;
}
}
}