+ 1
Canât use variables
So basicly when writing c++ code in code blocks, I try to use variables and it doesnât work. Iâm not sure why and any help would be great. Here is the code I have #include <iostream> using namespace std; int main() { int thevariable = 22; cout << âthevariableâ; return 0; } Ok so thats the code, in console after i run it and build, it only says âthevariableâ and not â22â, hopefuly this helps.
3 RĂ©ponses
+ 11
Remove the double quotes(" ")from the cout line.
cout<<thevariable;
-------
When you type the variable name enclosed in double quotes, the compiler thinks of it as a string literal and displays it as is.
When you just type the variable name (without the quotes), it displays the value of the variable.
+ 1
ahhh, thanks so much. I was so confused.