![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Newbie
Join Date: Mar 2005
Posts: 12
Rep Power: 0
![]() |
Newbie : need help with Dev-C++ compiler
Hi !
I am newbie trying to learn to code in C and I recently installed the Dev-C++ compiler I had a few questions about the compiler : I tried to use some C++ syntax and the compiler gave me an error, in the documentation i read that the MiniGW which is the compiler system used gcc for C compiling and g++ for C++ compiling The code is listed as follows : #include<iostream>
main()
{
cout << "Hello World";
return 0;
}The error I received was this : Quote:
"Does the dev-C++ compiler compile only C code , if not how can I make it do only that if possible ????? " Iam looking for a C compiler that compiles on only C code and not C++, I was using visual C++ before to compile before, the problem with VC++ is that it allows you to mix C and C++ code and doesn't complain about. It is also my fault to a great extent since I am trying to correct my programming style by being able to write code which is specific to C or C++ so any help with a C compiler would be appreciated. I am running windows XP |
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
There is virtually no compiler that compiles strictly C code and not C++, the problem isn't the compiler it's your code. Your code is incorrect and that's why it's not compiling it. It's not compiling your C++ code because the compiler thinks it's just fucked up C code or something.
You're forgetting to use the std namespace so cout and cin look undefined, you can make your program work one of two ways. Method A. Save yourself typing and use namespace STD, as follows: #include <iostream>
using namespace std;
int main() {
cout<<"Hello World!";
cin.get();
return 0;
}Method B. No STD namespace and cause yourself a hell of a lot more typing: #include <iostream>
int main() {
std::cout<<"Hello World!";
std::cin.get();
return 0;
}You shouldn't blame all the issues on your compiler, rather your code. Hope I clarified shit for you. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 12
Rep Power: 0
![]() |
yes u did , but then I have another one , how come the above code that i wrote compiles in VC++ but it doesn't in Dev-C++
1. I am guessing namespace is already default in VC++ but not in Dev-C++, if not what name space is Dev-C++ using 2. I am aware that MiniGW the compiler system in Dev-C++ has gcc (C compiler) and g++ (C++ compiler), this may sound stupid , but can i turn on off and still make the other one work. |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
|
Quote:
2nd question: Not sure. |
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Feb 2005
Posts: 86
Rep Power: 0
![]() |
i dont know that much about c++ cause im just learning also
but the first code you entered was correct except for #include<iostream> its supposed to be #include <iostream.h> with a space between #include and <iostream.h> and a ".h" after <iostream and dev c++ compiles both c and c++ |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Arod, no it isn't. There are two libraries: iostream.h and iostream. The latter is a newer version of the former.
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4
![]() |
or gemini shooter, u can code it like this:
#include<iostream> using namespace std; int main(){ cout << "Hello World" << endl; system("pause"); return 0; } |
|
|
|
|
|
#8 | ||
|
Hobbyist Programmer
|
Quote:
The C++ ANSI standard states that the .h appendencies are not needed in C++ programs. While the C ANSI standard says that the .h to header files are required. Hence, why that code will compile fine without the .h appended to iostream. This theory should also work fine for home-made libraries. For further proof, I suggest you look at the libraries of your compiler, specifically in the C++ section and you'll see they aren't .h files anyway. You need to read more. Quote:
It really frusterates me when people do (use system(); commands) that unless they're strictly using Winsock or Win32 programming because it cuts down the portability issues on the code. This is proper, easily portable code: #include <iostream>
using namespace std;
int main() {
cout<<"Hello World!";
cin.get();
return 0;
}Last edited by Mad_guy; Mar 4th, 2005 at 8:09 PM. |
||
|
|
|
|
|
#9 | |
|
Programmer
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Feb 2005
Posts: 86
Rep Power: 0
![]() |
i said i didnt know
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|