Book says one thing, compiler says another

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?
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
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.