how to put a string into an integer array c++

前端 未结 4 806
抹茶落季
抹茶落季 2021-01-03 14:27

I have a string that contains what ever the user has input

string userstr = \"\";
cout << \"Please enter a string \";
getline (cin, userstr);
<         


        
4条回答
  •  走了就别回头了
    2021-01-03 15:04

    You can just simply use isstringstream to convert the string to int as follows

    istringstream istringName(intString);
    istringName >> real_int_val;
    

    now it has magically become a int containing all numbers from string However I do not see why you would not cin it as a int in the first place??

提交回复
热议问题