Book says one thing, compiler says another
Feb 10, 2012 at 10:45pm Feb 10, 2012 at 10:45pm UTC
Hi! So I tried to create my first program using this 500+ page book beginners guide to c++.
Here is the code.
1 2 3 4 5 6 7 8 9 10
// Program 1.1
#include <iostream.h>
void main()
{
cout << "Hello! "
"Congratulations on your first"
" C++ program" ;
}
Unfortunately, it always says that I have one antiquated or deprecated header and that 'main' must return 'int'. Can any of you fix this problem for me?
Feb 10, 2012 at 10:49pm Feb 10, 2012 at 10:49pm UTC
Your book seem to old, and telling about pre-standard C++ stuff. You should either make:
1 2 3 4 5 6 7 8 9 10 11
// Program 1.1
#include <iostream>
using namespace std;
int main()
{
cout << "Hello! "
"Congratulations on your first"
" C++ program" ;
}
or
1 2 3 4 5 6 7 8 9 10 11
// Program 1.1
#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
cout << "Hello! "
"Congratulations on your first"
" C" ;
}
In order for your code to meet the standards.
Last edited on Feb 10, 2012 at 10:50pm Feb 10, 2012 at 10:50pm UTC
Feb 10, 2012 at 10:52pm Feb 10, 2012 at 10:52pm UTC
Certainly.
1 2 3 4 5 6 7 8 9 10 11
// Program 1.1
#include <iostream>
int main()
{
std::cout << "Hello! "
"Congratulations on your first"
" C++ program" ;
return 0;
}
Topic archived. No new replies allowed.