Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to define integer or double numbers from input argument

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading