Home | Projects | Notes > C++ Programming > String Manipulation
To use the C++ feature, we have to convert a string to a string stream. Then using getline() function we can do the task. The getline() function takes the string stream, another string to send the output, and the delimiter to stop the stream from scanning.
For example,
xxxxxxxxxx241234
5using namespace std;6
7int main(int argc, char *argv[])8{9 string str = "Hello, world! My name is Kyungjae Lee.";10 stringstream ss(str); // convert str into string stream11 12 vector<string> tokens;13 string tok;14 15 // tokenize using space as a delimiter16 while (getline(ss, tok, ' '))17 tokens.push_back(temp_str);18 19 // print tokens20 for (auto tok : tokens)21 cout << tok << endl;22 23 return 0;24}xxxxxxxxxx71Hello,2world!3My4name5is6Kyungjae7Lee.