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

前端 未结 4 827
抹茶落季
抹茶落季 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:09

    int* myarray = new int[ userstr.size() ];
    
    std::copy( usestr.begin(), userstr.end(), myarray ); 
    

    The terminating zero was not appended to the array. If you need it you should allocate the array having one more element and place the terminating zero yourself.

提交回复
热议问题