Why is my first program using dev-c++ not working?

3k Views Asked by At

I have installed devc++ and written a basic hello world program

#include<stdio.h>
int main
{
   cout<<"hello";
   return 0;
}

It is my run. However I am getting the following errors while running the code

3   1   D:\cpp\helloworld.cpp   [Warning] extended initializer lists only 
                                available with -std=c++11 or -std=gnu++11
4   4   D:\cpp\helloworld.cpp   [Error] 'cout' was not declared in this scope
5   4   D:\cpp\helloworld.cpp   [Error] expected unqualified-id before 
                               'return'
6   1   D:\cpp\helloworld.cpp   [Error] expected declaration before '}' token

Someone please help !

2

There are 2 best solutions below

0
On BEST ANSWER

In your first line of code, you use #include<stdio.h> which is a c preprocessor directive, but in main function you use cout<<"hello"; which is a C++ code.

For a C code, you need to use something like this:

#include <stdio.h>

int main(void)
{
    printf("hello");
    return 0;
}

And in the C++ (Read at C++ Language), you need to use something like:

#include <iostream>

int main() 
{
    std::cout << "hello";
    return 0;
}

Or

#include <iostream>
using namespace std;

int main() 
{
    cout << "hello";
    return 0;
}
0
On

Try this:

#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

Stuff like this should be easy to find on cplusplus.com http://www.cplusplus.com/forum/general/49600/