开发者

Dev-C++ compile errors

I want to use "Dev-C++" for compile c++ codes. So I download and install it, and write this code:

#include <iostream.h>

main () {
     cout << "124";
}

but when I compiled it, it said:

In file included from E:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, from [myfile path]\Untitled1.cpp:1: E:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.

After开发者_开发技巧 I saw errors, I change my code to this code:

#include <iostream>

main () {
     cout << "124";
}

but it said again that errors.

I compile first code easily in Turbo C++, BUT in Dev-C++ ...

What can I do?


First, make sure you write out the full definition of main, including the int return type. Leaving out the return type is an old, antiquated practice which doesn't fly these days.

Second, in the new-style headers—the ones missing the .h extension—the standard library is under the std namespace. There are two ways to make your program work:

1. Add an std:: qualifier to cout.

#include <iostream>

int main () {
    std::cout << "124";
}

2. Add a using declaration to allow unqualified references to the std namespace.

#include <iostream>

using namespace std;

int main () {
    cout << "124";
}


Make sure you put int in front of main () {

I believe any C/C++ program's main() function is required by POSIX and the appropriate language standards to return an int (someone correct me if I'm wrong).

EDIT: Also, be sure to include using namespace std; above int main ().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜