How to parse complex string with C++?

前端 未结 4 2095
小蘑菇
小蘑菇 2021-02-02 01:02

I\'m trying to figure out how could I parse this string using \"sstream\" and C++

The format of it is: \"string,int,int\".

I need to be able to ass

4条回答
  •  失恋的感觉
    2021-02-02 01:36

    It isn't fancy but you can use std::getline to split the string:

    std::string example("127.0.0.1,12,324");
    std::string temp;
    std::vector tokens;
    std::istringstream buffer(example);
    
    while (std::getline(buffer, temp, ','))
    {
        tokens.push_back(temp);
    }
    

    Then you can extract the necessary information from each of the separated strings.

提交回复
热议问题