#include <iostream>
#include <string>
using namespace std;

int main() {
	
    string mystring, token ;
    size_t cur_token=0, next_token ;
	mystring = "abc def ghi jklm nopq";  // fill 'mystring'

    do {
        next_token = mystring.find_first_of (" ", cur_token) ;
        token = mystring.substr (cur_token, next_token-cur_token);  // next_token-(nex_token==string::npos ? 0:cur_token) would be cleaner
        if (next_token!=string::npos) 
            cur_token = next_token+1; 
        //mystring = mystring.substr (next_token + 1) ;
        cout << token<<";"<<endl;
    } while (next_token!=string::npos);
    
}