PDA

View Full Version : Why I can't compile in dev-C++ 5.0 IDE??


zaracattle
07-07-2006, 10:20 AM
I installed DEv-C++ 5.0,but when I pressed F9 to run ,the program has some errors that I can't understand why??Even though my code is true.Other codes have the same errors.Ex:
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
class Count{
public:
int x;
void print (){cout << x << endl;}
};
void main(){
Count counter,
*counterPtr = &counter,
&counterRef = counter;

cout<<"Gan 7 den x va insu dung ten cua doi tuong";
counter.x = 7;
counter.print();
cout<<"Gan 8 den x va in su dung 1 tham khao";
counterRef.x=8;
counterRef.print();

cout<<"Gan 10 den x va in su dung 1 con tro";
counterPtr -> x =10;
counterPtr -> print();
getch();
}
When I compile it ,In the bottom table of program ,it informed that "In file included from C:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31, from bai2.cpp(title of program) , this information(may be no important: "#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 <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. " And a lots of other errors... like "main must return int",...

In the first time ,when I compiled this program ,it still ran well,but after that I closed this program,when I opened Dev-C++ again then it didn't work.I don't understand why??I checked the path of include,lib,bin, it is true,no problem.Anybody has way to fix it,please show me,thanks very much!!!!!

rpgfan3233
07-07-2006, 05:37 PM
Read the errors:
"This file includes at least one deprecated or antiquated header. . . ., or <iostream> instead of the deprecated header <iostream.h>." ("deprecated" means outdated, in case you didn't know)
"main must return int" (per the standard, it should be 'int main()', not 'void main()' )

Also, the standard introduced the use of namespaces as well, so if you wish to use C++ streams, functions, etc., such as 'cout' or 'vector', it has become 'std::cout' and 'std::vector'. To get around this, add this line after your include files:
using namespace std;

zaracattle
07-08-2006, 02:42 AM
So this compiler don't support "void main()" mode,but some times I compiled this code and no problem happened,but sometimes I couldn't compile it.I don't understand why???

rpgfan3233
07-08-2006, 04:04 AM
This seems to be a problem with Dev-C++. Have you updated it at all, at least gcc-core and gcc-g++ (current Devpak version is 3.4.2)? Before you download, tell us what gcc version you are compiling with by compiling gccVersion.c:

#include <stdlib.h>

int main (void) {
system("c:\\dev-c++\\bin\\gcc.exe --version >gcc.txt");
system("c:\\dev-c++\\bin\\g++.exe --version >g++.txt");
printf("gcc and g++ versions outputted to gcc.txt and g++.txt\n");
return 0;
}


I currently have both gcc 3.4.2 and my own homebrew of gcc 4.1.1 (I can't remember how I made it, :p).

zaracattle
07-08-2006, 04:11 AM
version beta 9.2,I tried updating server but the program informed that server couldn't connect although I connected Internet...

zaracattle
07-09-2006, 11:21 AM
It is 3.4.2 version,g++.exe (GCC) 3.4.2 (mingw-special)... (gcc is, too)

rpgfan3233
07-10-2006, 04:57 PM
gcc/g++ 3.4.2 should work fine. Your only real problem right now is that you should declare "int main()", not "void main()". Also, if you wish to use iostream.h and things like that, you may wish to do this:

Tools -> Compiler Options -> put a check mark in the check mark control next to "Add the following commands when calling compiler" -> type "-Wno-deprecated" (without the " characters) in the text box below that check mark control

frog.frog
07-21-2006, 06:20 AM
I use Dev, too. Your problem is both <iostream.h> and void main(). DevCPP doesn't like main returning void, and uses <iostream> without a .h trailing it. If Dev ever gives you an error about deprecated or antiquated headers, try removing (or adding, as the case may be) .h.

rpgfan3233
07-21-2006, 07:24 AM
C++ libraries have no ".h" at the end ("iostream" instead of "iostream.h"), and the standard C libraries are just the letter 'c' preceding the name of the library ("cstdlib" instead of "stdlib.h"). This is actually a part of the standard, which g++ follows generally (g++ is the actual compiler, the backend of Dev-C++, which is is the IDE).

As for main() returning an integer instead of being declared void, this is actually done because the program has an error in the main() thread, which allows developers to return a value other than 0 if execution did not complete properly.