C++ | main function error | beginners -


this question has answer here:

i'm totally new c++ , i'm using eclipse.

but... don't know why error @ main function:

error: ::main must return int

my code is:

void main() { char a; while (a!='q') {     string ln = "enter option: ";     cout<< ln;      switch(a)     {     case 1:         if (a=='1')             func1();         break;     case 2:         if (a=='2')             break;         break;     } } } 

because in c++, main function must have return type of int.

your version return type of void incorrect , being correctly rejected compiler.

just change declaration from

void main() 

to

int main() 

there alternative form allows process arguments passed on command line program. looks this:

int main (int argc, char *argv[]) 

but when you're learning c++ , trying print "hello world" on screen, not need worry about. you'll there eventually.

and consider updating book you're using learn c++, too. if it's getting function signature of entry point wrong, other more complicated things might getting wrong?! no point in learning language wrong first time around. list of suggested books available here.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -