How do you search a std::string for a substring in C++?

后端 未结 6 779
南方客
南方客 2020-12-10 16:34

I\'m trying to parse a simple string in C++. I know the string contains some text with a colon, followed immediately by a space, then a number. I\'d like to extract just t

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 17:32

    const std::string pattern(": ");
    std::string s("Sectors: 4095");
    size_t num_start = s.find(pattern) + pattern.size();
    

提交回复
热议问题