Converting string to int without getting memory permission error

I have this function:

template<typename T>
T toIntegralType(const std::string &str) {
static_assert(std::is_integral::value, “Integral type required.”);
T ret;
std::stringstream ss(str);
ss >> ret;
return ret;

But I get a memory permission error when trying to convert a string to an int. Any solutions or anything else I can try? I’m using vexcode pro.

Use the stoi() function. Since VEXCode is C++ the majority of the C++library and API applies. So you can do a google search “how to convert string to int in C++” to find an answer.

int myInt = stoi(myString);

that function doesn’t show as available for me. When I type it in, I get a “No matching function for call to ‘stoi’”. atoi also doesn’t work.

Edit: using std::stoi also doesn’t work.

Edit Edit: Nevermind, I was passing in std::string and not char*

1 Like