Answers for "libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion"

C++
0

libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion

#include <string>
#include <typeinfo>
// remove empty spaces in string you want to convert
string dirtystring = " 13 ";
std::string cleanstr = dirtystring;
cleanstr.erase(remove(cleanstr.begin(), cleanstr.end(), ' '), cleanstr.end());
dirtystring = str2;

// Proceed to converting it to an int using stoi
// Convert string to int
int n;
stringstream ( strr ) >> n;
cout << n; //Output:13
// Check the type requires #include <typeinfo>
cout<<typeid(n).name()<<endl; //Output: i
Posted by: Guest on October-05-2021

Browse Popular Code Answers by Language