How to parse complex string with C++?

前端 未结 4 2103
小蘑菇
小蘑菇 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:29

    You could do something like this as well I believe (Totally off the top of my head so apologies if i made some mistakes in there) ...

    stringstream myStringStream( "127.0.0.1,12,324" );
    int ipa, ipb, ipc, ipd;
    char ch;
    int aNumber;
    int bNumber;
    myStringStream >> ipa >> ch >> ipb >> ch >> ipc >> ch >> ipd >> ch >> aNumber >> ch >> bNumber;
    
    stringstream someStringStream;
    someStringStream << ipa << "." << ipb << "." << ipc << "." << ipd;
    string someString( someStringStream.str() );
    

提交回复
热议问题