Reaching a specific word in a string

后端 未结 2 1889
醉酒成梦
醉酒成梦 2021-01-24 22:53

Hi I have a string like this:

word1--tab--word2--tab--word3--tab--word4--tab--word5--tab--word6

I need to extract the third word fr

2条回答
  •  被撕碎了的回忆
    2021-01-24 23:17

    std::string has the find method which returns an index. You can use

     find("--", lastFoundIndex + 1)
    

    three times to find the start index of your word, a fourth time for the end index, and then use substr.

提交回复
热议问题