Next Generation Emulation banner
1 - 12 of 12 Posts

·
Registered
Joined
·
17 Posts
Discussion Starter · #1 ·
Hi there Im new to programming or what they called the noob I just want to know something about C++ I don't understand whats the difference between
#include <iostream.h> to
#include <iostream>
When will i be going to use <iostream.h> and when will i be going to use <iostream>

and also difference between int main() and void main()

can i ask a favor can u teach me C++ programming where did u learn it?
thank you in advance...plsss don't post links i need your answers...
 

·
War Games coder
Joined
·
1,927 Posts
Between #include <iostream.h> and #include <iostream>, the difference is... well, not much. The #include <iostream> is the new way to do things, which is fully backwards compatible with #include <iostream.h>... only you'll have to include a namespace for which pieces you're using.

For example, when you use #include <iostream> and you're using cout, you need one of the following:

using std::cout;
using namespace std;

If you just #include <iostream.h>, you don't need to worry about it.

Between int main() and void main(), the difference is whether or not your program will return an error code. Generally, if something happens to your program that doesn't normally happen, you return a non-zero value from your main() function. You cannot do this with a void main(). You can check the return value of the last program run from the shell through the variable $?.

For example, consider the following program:
Code:
#include <iostream>
#include <cstring>
 
using std::cout;
using std::cin;
using std::endl;
 
int main (int argc, char ** argv)
{
   cout << "Did I work correctly? (yes or no)" << endl;
   char Input[4];
   cin >> Input;
   if(!strcmp(Input, "yes"))
   {
      return 0;
   }
   return 1;
}
Now, compile and run the program in a shell. After completing the program, type "echo $?", and either a 0 or a 1 should appear. Is it clearer now?

EDIT: It appears that the windows shell has been castrated. An "echo $?" echoes $? instead of the return value of the last program. You'll have to use this example under unix. This does not mean that Windows doesn't use the return value, but that you can't use a simple echo command to see it.
 

·
Registered
Joined
·
116 Posts
Always use <iostream> in new code.
In addition to what KillerShots already stated, <iostream> and <iostream.h> have some differencies regarding the interfaces (so both can't co-exist in a program), and <iostream> supports wide characters where <iostream.h> only supports char ...
If you have a program which already uses <iostream.h>, stick with it. Otherwise use <iostream> ;)
 

·
Registered
Joined
·
17 Posts
Discussion Starter · #5 ·
so your saying #include <iostream> is more efficient to use and is updated than <iostream.h>..If i use <iostream.h> i will not include anymore using namespace std; but when i will use <iostream> i will include it..is that right?....so when will i be going to use void main and int main?...thank you your helping me a lot..btw were can i find the best site to study c++....Mr. Killershots were did you learn programming..?
 

·
War Games coder
Joined
·
1,927 Posts
You have the right idea with the #include <iostream> and #include <iostream.h>.

You use int main() if you're going to consider returning an error code, and void main() when you simply don't care (but not all compilers work with void main()).

I learned C++ mostly in a local community college (Brevard Community College), and a little more in the university I graduated from (Florida Institute of Technology). I used the "C++ How to Program" 2nd edition from Dietel & Dietel in both cases, though they have later editions by now. It's an OK book for reference, but not so great for learning from. I learned the most from asking questions in class.
 

·
Registered
Joined
·
17 Posts
Discussion Starter · #7 · (Edited)
Thank you for your nice explanation your helping me alot... now i understand now how to use this char. Im giving it a try now...so you learned C++ in local community college (Brevard Community College), and a little more in the university and by using C++ book. Did you also learned C++ through the internet??
I still have a lot of question to ask but for now i will try first what have you taught me..If I don't understand something i will just post them here...thank you for your great help...BTW what are you using for compiling...me Im currently using Dev-C++ is it a good compiler?
 

·
Knowledge is the solution
Joined
·
7,484 Posts
Dev-C++ itself isn't a compiler really, but a IDE (Integrated Development Environment). In short, it is just a GUI that provides some editing tools and automated compiling. The compiler Dev-C++ uses is mingw, which yes, it's one of the best compilers out there.
 

·
War Games coder
Joined
·
1,927 Posts
MinGW is a decent free compiler. It has some problems with inherittance and templates (only when together - handles them fine separately), but nothing that can't be worked around.

gcc (which MinGW is heavily based off of) is the best option (not subject to the problems mentioned above), but if I remember correctly, MinGW is the windows port of gcc.

Personally, I've never used dev-C++, but I hear it's not bad.

Also, if you can afford it, Visual Studios is a good IDE - very good debugger and good built-in cross-referencing tools. Another good free option is Eclipse. I'd mention many others, but I see that you're running Windows and the others don't work under Windows.

I did learn quite a few topics from the internet, but not many of the basics. My favorite sites were:
  • Gametutorials - It was free when I used it, but they now charge for their tutorials
  • FreeDevs - When gametutorials started charging, we made a new site and started making tutorials for it for free. I contributed most of the threading tutorials there.
  • NeHe - arguably the best C++ tutorial site around for gaming
Does that help some?
 

·
Registered
Joined
·
17 Posts
Discussion Starter · #10 ·
So dev-c++ is not good at all but ill stick to it for now because im still a noobie and still studying the basics of C++...is that okey....I will buy Microsoft visual studios when i have enough knowledge in c++ and when im going to create a big project (help me out when that day comes)....thank you for the suggestions...Btw the sites that you mentioned are good but Gametutorials are charging and i think i can learn a lot there...for freedevs it is also a good site bec. i can download them to my computer and read them with comfort....thank you very much your helping me alot...
 

·
War Games coder
Joined
·
1,927 Posts
I don't think anyone said dev-c++ is no good - I just said I don't have any personal experience with it.

I also note that something called Code::Blocks is floating around - may be worth looking at (again, I've never tried it).
 
1 - 12 of 12 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top