c++ - split a sentence so that adds each word in an array item -



c++ - split a sentence so that adds each word in an array item -

i have sentence, want split sentence adds each word in array item. have done next code still wrong.

string str = "welcome computer world."; string strwords[5]; short counter = 0; for(short i=0;i<str.length();i++){ strwords[counter] = str[i]; if(str[i] == ' '){ counter++; } }

i'm answering since should larn mistakes: utilize += string operator , code work:

// strwords[counter] = str[i]; <- alter strwords[counter] += str[i]; <-

to remove spaces (if don't want append them) alter order of space check, like:

for (short = 0; i<str.length(); i++){ if (str[i] == ' ') counter++; else strwords[counter] += str[i]; }

anyway i'm suggesting utilize duplicate link how split string in c++? too

c++ arrays split

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -