简体   繁体   English

我的项目中从 const char 到 int 错误的无效转换

[英]Invalid conversion from const char to int error on my project

#include <iostream>

using namespace std;

int
main ()
{
  int number1, number2, sumatotala, choose, add, multiply;
  add = "add";
  multiply = "multiply";
  
  cin>>choose;
  cin>>number1;
  cin>>number2;
  
  if(choose = add) cout<<number1+number2;
  if(choose = multiply) cout<<number1*number2;

  return 0;
}

This is my code and I have the next error.这是我的代码,我有下一个错误。 main.cpp:17:9: error: invalid conversion from 'const char*' to 'int' [-fpermissive] add = "add"; main.cpp:17:9: 错误:从 'const char*' 到 'int' 的无效转换 [-fpermissive] add = "add"; ^~~~~ main.cpp:18:14: error: invalid conversion from 'const char*' to 'int' [-fpermissive] multiply = "multiply"; ^~~~~ main.cpp:18:14: 错误:从 'const char*' 到 'int' 的无效转换 [-fpermissive] multiply = "multiply"; ^~~~~~~~~~ ^~~~~~~~~~

I want to make a little program that lets u choose multiply or add and based on your decision multiply or add the 2 numbers.我想做一个小程序,让你选择乘法或加法,并根据你的决定乘法或加法 2 个数字。 I don't code that well and if someone could help me I would be very gratefull.我的编码不太好,如果有人可以帮助我,我将不胜感激。

add = "add";            
multiply = "multiply";

Here you need to either use numbers as values (because these are integer variables) or if you need them as strings, you have to remove them from the above line and write them like this:在这里,您需要使用数字作为值(因为它们是整数变量),或者如果您需要将它们作为字符串,则必须将它们从上面的行中删除并像这样写:

std::string add = "add";
std::string multiply = "multiply";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM