How to extract mixed format using istringstream

后端 未结 4 658
独厮守ぢ
独厮守ぢ 2021-01-19 03:05

Why does my program not output:

10
1.546
,Apple 1

instead of

10
1

here\'s my program

4条回答
  •  后悔当初
    2021-01-19 03:52

    You should do the below changes:

    string str = "10  1.546 Apple 1";
    

    And

     stream >> a >> b >> dummy >> c;
    

    In your example, dummy would have got the string ",1.546,Apple" . Because till a non-numeric char is encountered, it is fed to variable a. After that everything is added to dummy ( a string ) until the default delimiter (space) is reached

提交回复
热议问题