terminate called after throwing an instance of 'std::invalid_argument'
I want to convert a string to an array of integers. The following is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string num1="";
cout<<"enter a number: ";
cin>>num1;
int a[10];
for (int i=0; i<10; i++)
{
a[i]=stoi(num1.substr(i,i));
}
for (int i=0;i<10;i++)
{
cout<<a[i];
}
system("pause");
return 0;
}
|
The code above causes the following errors,
terminate called after throwing an instance of 'std::invalid_argument'
what (): stoi
Aborted (core dumped)
after running. Could someone help me? Thank you!
Last edited on
Thank you! I fixed it. ^^
Topic archived. No new replies allowed.