How to split string using istringstream with other delimiter than whitespace?

前端 未结 3 1201
醉话见心
醉话见心 2020-12-23 09:34

The following trick using istringstream to split a string with white spaces.

int main() {
    string sentence(\"Cpp is fun\");
    istringstream         


        
3条回答
  •  别那么骄傲
    2020-12-23 10:02

    #include 
    #include 
    #include 
    
    int main()
    {
      std::istringstream iss { "Cpp|is|fun" };
    
      std::string s;
      while ( std::getline( iss, s, '|' ) )
        std::cout << s << std::endl;
    
      return 0;
    }
    

    Demo

提交回复
热议问题