invalid operands to binary expression ('int' and 'string'

when i run my program I get the following errors:

"invalid operands to binary expression ('int' and 'string')" and "no viable conversion from 'int' to 'string'"

this is the part of the code where I get the errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
char shift(char c, string keyWord){ // Shifts the order of the letters

	int result = (c-'A' + keyWord);

	if (result >= 26) result = result - 26;
	if (result < 0) result = result + 26;
	
	return result + 'A';
}

string keyWord = atoi(argv[2]);
  bool encrypt;
  string option(argv[1]);
  string line;
  string encodedLine;	
  if (option == "-e"){
    encrypt = true;
  }	else {
    encrypt = false;
  }
  


the second part of the code is where i get the second error
Last edited on
You are trying to use the + operator with the integer c-'A' and the string keyWord. There is no such version of the + operator.
what do you mean?
You cannot use + to add a number to a string - you have to convert the number to a string and then use + to add the strings together.
ok
Topic archived. No new replies allowed.