How to split a string by whitespaces in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to split a string by whitespaces in C++?

I want to split a string, "This is a string", in separated words by whitespaces.

6th Sep 2020, 4:22 PM
Martín Santiago P
Martín Santiago P - avatar
2 Answers
+ 2
unlike java and python you can’t use split(), google the strtok() function for c and c++
6th Sep 2020, 4:29 PM
Roderick Davis
Roderick Davis - avatar
+ 1
You can compare like so If (character == ' ') Then add word to array. If you try to work out an implementation of your own i could provide some more help
6th Sep 2020, 5:01 PM
Robert Atkins
Robert Atkins - avatar