Stoi cause an exception

I have a function that reads from a file and converts the string to an int. I am using stoi and when i test this function out it like on repl.it it works but when i run it on my robot i says and exception has occured: stoi. I have the proper header file included for stoi. is it just a vex brain thing?

1 Like

I’m not quite sure the reason but I’ve never had great success in using Strings with C++ on the vex brain. It is possible that there is some other issue though. Could you possibly supply your code so we can take a look?

How exactly are you reading from the file?

Make a catch for the conversion so the exception is handled.

try{
    Number = std::stoi(String);
}
catch(...){
    std::cout << "Tried to convert non-number";
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.