How to convert a command-line argument to int?

前端 未结 7 1925
难免孤独
难免孤独 2020-12-01 03:18

I need to get an argument and convert it to an int. Here is my code so far:

#include 


using namespace std;
int main(int argc,int argvx[]) {         


        
7条回答
  •  再見小時候
    2020-12-01 04:05

    Like that we can do....

    int main(int argc, char *argv[]) {
    
        int a, b, c;
        *// Converting string type to integer type
        // using function "atoi( argument)"* 
    
        a = atoi(argv[1]);     
        b = atoi(argv[2]);
        c = atoi(argv[3]);
    
     }
    

提交回复
热议问题