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

前端 未结 4 833
抹茶落季
抹茶落季 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 14:51

    You can access each element in your string using the [] operator, which will return a reference to a char. You can then deduct the int value for char '0' and you will get the correct int representation.

    for(int i=0;i

提交回复
热议问题