I'm new to C++, and this question will probably seem trivial to many, but please keep in mind I am just starting the C++ language.
I have assigned a variable x
to equal 20
and want to concatenate it with a string. My C++ code is below.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
int x = 20;
int y = 15;
if (x >= y) {
cout << x + " is greater than " + y;
}
}
My expected outcome would be 20 is greater than 15
, but what instead comes up is some odd é@
. I'm confused, and I couldn't find a solution on GeeksForGeeks, w3schools, or the rest of SO.
I understand that using cout << x << " is greater than " << y;
works just fine, but I'm not sure why concatenation doesn't work here. Also, why do these odd characters come out instead?
Thanks in advance.
(Also, please don't leave an answer without answering the question. I remember when starting JS I asked a question and the only answer was "don't use document.write
." While I get that, it would be far better to actually answer the question and put that as a side note.)