Reaching a specific word in a string

后端 未结 2 1890
醉酒成梦
醉酒成梦 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:07

    assuming "tab" is \t;

    std::istringstream str(".....");
    std::string temp, word;
    
    str >> temp >> temp >> word;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题