Skip to content

Instantly share code, notes, and snippets.

@Linkaan
Created October 28, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linkaan/c453246275c938149b44 to your computer and use it in GitHub Desktop.
Save Linkaan/c453246275c938149b44 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
int main ()
{
std::vector<std::string> tokens;
std::vector<std::string>::iterator it;
std::string str ("homework! my do Please");
char * cstr = new char [str.length()+1];
std::strcpy (cstr, str.c_str());
char * p = std::strtok(cstr," ");
while (p!=0)
{
tokens.push_back(p);
p = std::strtok(NULL," ");
}
for (it=tokens.end()-1; it>=tokens.begin(); it--)
std::cout << ' ' << *it;
std::cout << '\n';
delete[] cstr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment