i am trying to change a provided example of a c++ commandline program to accept another argument. the problem i am having is that it does not accept inputs <1 >0 like float values.
since i have basically no clue about c++ it is probably an easy fix, but just if you knwo how 😉
originally the working part looked like this:
double lOffset = 0.1;
PtrVector offset_poly_with_holes = createPolygon(lOffset, pwh, speeds);
what i did then is then moved the lOffset = 0.1 to the beginning of the code and added a new argument like so :
for (int i = 1; i < argc; ++i)
{
// here are all the other arguments
else if (!strcmp("-d", argv[i]) && i < argc_check)
{
lOffset = std::stoi(argv[++i]);
}
}
so when i hardcode 0.1 or 1 for example the code works. when i pass 0.1 as an argument it does not work. when i pass anything with integer numbers it works.
I assume that something is wrong with the types when it comes from an argument?
Thank you so much for help!
>Solution :
stoi() stands for string to integer. The equivalent function for floats is stof().