Operand Error ==

no operator "==" matching this operand
VS express 2013 Desktop

1
2
3
4
5
6
7
8
9
10
11
12
  if (choicegamemode == 1)  // first line that has error
{
//code
}
else if (choicegamemode == 2) // second line with error
{
//code
}
else
{
//code
}


I have:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <windows.h> 


I tried only having "=" but then i get: Expression must have a bool type.
Last edited on
Could you please provide a small example of code that recreates this error? You havent even shown us what "choicegamemode" is.
1
2
3
4
5
6
7
8
9
std::string choicegamemode;

//lots of code

std::cout << "How many people are playing?" << endl;

		std::cin >> choicegamemode;

		if (choicegamemode == 1) 
Last edited on
You are attempting to compare an integer to a string.
Is "fubar" less, equal, or more than 42?

The std::string has three versions of operator==
See http://www.cplusplus.com/reference/string/string/operators/

The other operand would have to have one of those types.


However, why do you read a string at all?
You clearly want the user to give you an integer.
Therefore, read an integer.
Topic archived. No new replies allowed.