Jun 10, 2013 at 3:55pm UTC
The included code does not compile on my 12-11 Codebooks. What's wrong?
#include <iostream>
using namespace std;
int main()
{
auto Flag = true;
auto Number = 2500000000000;
cout << "Flag = " << Flag;
cout << " , sizeof(Flag) = " << sizeof(Flag) <<endl;
cout << "Number = " << Number;
cout << " , sizeof(Number) = " << sizeof(Number) << endl;
return 0;
}
error: Flag does not name a type, latter Flag not declared
The same for Number.
Last edited on Jun 10, 2013 at 5:01pm UTC
Jun 10, 2013 at 4:03pm UTC
What error message do you get?
Jun 10, 2013 at 4:10pm UTC
The code looks fine. If you get any errors, that's not because of the syntax, but probably because of some issues with the compiler. Try using Microsoft Visual Studio 2010 or 2012 Express instead.
Jun 10, 2013 at 4:21pm UTC
> What's wrong?
Enable C++11.
In Settings => Compiler => Flags check -std=c++11
While you are at it, also check these three -Wall
-Wextra
-pedantic-errors
Last edited on Jun 10, 2013 at 4:23pm UTC
Jun 30, 2013 at 2:34am UTC
This is different than your earlier example but...
The compiler can't determine the type of "variable" (i.e., what type "auto" should be replaced by) since you aren't assigning anything to it.
Jun 30, 2013 at 5:33am UTC
> and when I set the variable to 0, it only returns numbers.
When we use auto
in this manner, we ask the compiler to deduce the type of a variable from the type of its initializer.
So this is an error; there must be an initializer: auto variable;
And with auto variable = 0 ;
, the type of variable
is deduced to be int
Jul 6, 2013 at 4:24pm UTC
I have been away from my lessons for a few days and now when I run the program it compiles OK. Thank you all for your help.