Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 3rd, 2005, 8:13 PM   #1
gemini_shooter
Newbie
 
Join Date: Mar 2005
Posts: 12
Rep Power: 0 gemini_shooter is on a distinguished road
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:
C:\Documents and Settings\Saurav Batra\My Documents\Code\TestCode\test.cpp In function `int main()':
5 C:\Documents and Settings\Saurav Batra\My Documents\Code\TestCode\test.cpp `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
Here are the questions that popped up :

"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
gemini_shooter is offline   Reply With Quote
Old Mar 3rd, 2005, 10:26 PM   #2
Mad_guy
Hobbyist Programmer
 
Mad_guy's Avatar
 
Join Date: Oct 2004
Location: Sandstorm, Techno Club
Posts: 239
Rep Power: 4 Mad_guy is on a distinguished road
Send a message via AIM to Mad_guy Send a message via MSN to Mad_guy
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.
Mad_guy is offline   Reply With Quote
Old Mar 4th, 2005, 2:14 AM   #3
gemini_shooter
Newbie
 
Join Date: Mar 2005
Posts: 12
Rep Power: 0 gemini_shooter is on a distinguished road
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.
gemini_shooter is offline   Reply With Quote
Old Mar 4th, 2005, 4:14 PM   #4
Mad_guy
Hobbyist Programmer
 
Mad_guy's Avatar
 
Join Date: Oct 2004
Location: Sandstorm, Techno Club
Posts: 239
Rep Power: 4 Mad_guy is on a distinguished road
Send a message via AIM to Mad_guy Send a message via MSN to Mad_guy
Quote:
Originally Posted by gemini_shooter
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.
1st question: Dev-CPP isn't using a "namespace," the 'std' namespace is a part of the ANSI C++ libraries and is included, once you get into programming with C++ more you'll understand exactly what namespaces are and how you can code them yourself. They're basically a way to refer to sections and hunks of all sorts of code. Classes, functions, constants ect, ect... I assume VC++ just searches through ALL the C++ libraries until it finds the cout and cin functions, and that's why it compiles them even if you don't specify what the namespace of which cout and cin are located is.

2nd question: Not sure.
Mad_guy is offline   Reply With Quote
Old Mar 4th, 2005, 5:09 PM   #5
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
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++
arod199113 is offline   Reply With Quote
Old Mar 4th, 2005, 5:46 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Arod, no it isn't. There are two libraries: iostream.h and iostream. The latter is a newer version of the former.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 4th, 2005, 8:04 PM   #7
BaroN NighT
Programmer
 
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4 BaroN NighT is on a distinguished road
or gemini shooter, u can code it like this:

#include<iostream>

using namespace std;

int main(){
cout << "Hello World" << endl;

system("pause");
return 0;
}
BaroN NighT is offline   Reply With Quote
Old Mar 4th, 2005, 8:05 PM   #8
Mad_guy
Hobbyist Programmer
 
Mad_guy's Avatar
 
Join Date: Oct 2004
Location: Sandstorm, Techno Club
Posts: 239
Rep Power: 4 Mad_guy is on a distinguished road
Send a message via AIM to Mad_guy Send a message via MSN to Mad_guy
Quote:
Originally Posted by arod199113
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++
That's incorrect.

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:
Originally Posted by BaroN NighT
or gemini shooter, u can code it like this:

#include<iostream>

using namespace std;

int main(){
cout << "Hello World" << endl;

system("pause");
return 0;
}
I would rather you not use a system(); call in that program.

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.
Mad_guy is offline   Reply With Quote
Old Mar 4th, 2005, 8:09 PM   #9
BaroN NighT
Programmer
 
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4 BaroN NighT is on a distinguished road
Quote:
Originally Posted by arod199113
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++
C++ ignores spaces so there's no differences between #include<iostream> (without space) and #include <iostream> (with spaces)
BaroN NighT is offline   Reply With Quote
Old Mar 4th, 2005, 8:21 PM   #10
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
i said i didnt know
Quote:
i dont know that much about c++ cause im just learning also
arod199113 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC