Show split.cc syntax highlighted
#include <string>
#include <vector>
#include <iostream>
using std::cout;
using std::endl;
bool split_args(const std::string &s,
std::vector<std::string> *args)
{
int pos, npos;
pos = 0;
while(pos < s.length()) {
npos = s.find_first_of(' ', pos);
args->push_back(s.substr(pos, npos-pos));
pos = s.find_first_not_of(' ', npos);
}
return true;
}
int main()
{
std::string a("this is a test");
std::string b("This is another test");
std::vector<std::string> args;
std::vector<std::string>::iterator i;
args.clear();
split_args(a, &args);
cout << "Args from a:" << endl;
for(i=args.begin(); i!=args.end(); i++)
cout << "\t-->" << *i << "<--" << endl;
args.clear();
split_args(b, &args);
cout << "Args from b:" << endl;
for(i=args.begin(); i!=args.end(); i++)
cout << "\t-->" << *i << "<--" << endl;
return 0;
}
See more files for this project here