'Prevent a string with from being cast to an int with try/catch [duplicate]
I am using try/catch exception to sort a vector of strings and I want to prevent it from converting a string like "157cm" from being converted to an int. It removes the "cm" part. Is there anyway to prevent this?
My code:
for (int v = 0; v < values.data.size(); v++) {
try
{
int value = std::stod(values.data.at(v));
values.areints2.push_back(value);
}
catch (std::exception& e)
{
string x;
x = values.data.at(v);
values.notints2.push_back(x);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
