Convert character array to float?

前端 未结 3 826
半阙折子戏
半阙折子戏 2021-01-15 09:21

I\'m writing a very basic command line C++ application that takes arguments on execution.

I just started C++ today, and it seems apparent that you can only take

3条回答
  •  春和景丽
    2021-01-15 09:55

    A char** in C++ is just that, an pointer to a pointer to a character, thus not convertable to a float (Or any numeric value for that matter) directly Thus your first example will fail. You can use the intermediary functions atof or strtof (note strtof, not stof, why your second example fails) to convert these values, assuming you are sure they are actually in float form.

提交回复
热议问题