bremea
December 4, 2021, 3:49pm
1
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.
Connor
December 4, 2021, 4:24pm
2
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);
3 Likes
bremea
December 4, 2021, 4:54pm
3
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