fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. string mystring, token ;
  8. size_t cur_token=0, next_token ;
  9. mystring = "abc def ghi jklm nopq"; // fill 'mystring'
  10.  
  11. do {
  12. next_token = mystring.find_first_of (" ", cur_token) ;
  13. token = mystring.substr (cur_token, next_token-cur_token); // next_token-(nex_token==string::npos ? 0:cur_token) would be cleaner
  14. if (next_token!=string::npos)
  15. cur_token = next_token+1;
  16. //mystring = mystring.substr (next_token + 1) ;
  17. cout << token<<";"<<endl;
  18. } while (next_token!=string::npos);
  19.  
  20. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
abc;
def;
ghi;
jklm;
nopq;