これはC++コンソールスニペットです。
ユーザー入力に応じて、いくつかの関数の中から関数保持パラメーターを呼び出したいと思います。
例えば:
#include<iostream>
using namespace std;
void Add (int x, int y)
{
cout << x + y << endl;
}
void Subs (int x, int y)
{
cout << x - y << endl;
}
int main(int argc, char* argv[])
{
// Variable initialization
char calc_type;
int x;
int y;
// Console input
cout << "Add or Substract (a or s)?" << endl;
cin >> calc_type;
cout << "1st number" << endl;
cin >> x;
cout << "2nd number" << endl;
inc >> y;
if (calc_type == "a")
{
Add(x, y);
}
else
{
Subs(x, y);
}
return 0;
}
しかし、これを書いていると、次のようなエラーメッセージが返されます。
エラーC2446:'==':'constchar*'から'int'への変換なし
この変換が可能なコンテキストはありません
エラーC2040:'==':'int'は、間接参照のレベルが' constchar[2]'と異なります。
この問題にどのように対処できますか(おそらく参照またはポインターが優先されます???)
ありがとうございました