The easiest way to read formatted input in C++?

后端 未结 4 977
醉酒成梦
醉酒成梦 2021-01-17 08:37

Is there any way to read a formatted string like this, for example :48754+7812=Abcs.

Let\'s say I have three stringz X,Y and Z, and I want



        
4条回答
  •  自闭症患者
    2021-01-17 09:05

    #include 
    #include 
    
    int main(int argc, char **argv) {
      std::string str = ":12341+414112=absca";
      std::stringstream ss(str);
      int v1, v2; 
      char col, op, eq; 
      std::string var;
      ss >> col >> v1 >> op >> v2 >> eq >> var;
      std::cout << v1 << " " << v2 << " " << var << std::endl;
      return 0;
    }
    

提交回复
热议问题