小编Rob*_*Rob的帖子

c ++的整数参数

我在C++中有一种计算器,它应该在执行时接受参数.但是,当我输入7作为参数时,当放入变量时它可能会变成10354.这是我的代码:

#include "stdafx.h"
#include <iostream>

int main(int argc, int argv[])
{
    using namespace std;
    int a;
    int b;
    if(argc==3){
        a=argv[1];
        b=argv[2];
    }
    else{
        cout << "Please enter a number:";
        cin >> a;
        cout << "Please enter another number:";
        cin >> b;
    }
    cout << "Addition:" << a+b << endl;
    cout << "Subtaction:" << a-b << endl;
    cout << "Multiplycation:" << a*b << endl;
    cout << "Division:" << static_cast<long double>(a)/b << endl;
    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ arguments

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

arguments ×1

c++ ×1