Lots and lots of help needed here!

Started by
18 comments, last by b0iNg 21 years, 1 month ago
Ok..I downloaded Dev-C++ and I am closely following a tutorial of the net "Learn C++ in 21 days". The link to it is here: http://newdata.box.sk/bx/c/ Ok so I install dev-c++..did the first hello world application and compile it..then ERROR! Could not find iostream.h ..the tutorial said to check the documentation for info on how to include paths or something..how do I do it? I'm totally confused. Whats more I think this dev-c++ is for C, not C++ programming as the tutorials they show is in C(I think). Also the tutorial uses "cout" while the dev-C++ tutorial uses "printf"..and the program detects "cout" as an error? The code is: #include <iostream.h> int main() { cout << "Hello World!\n"; return 0 } And when I try compiling it it says that it cannot find "iostream.h" and that there is an error with the line "cout << "Hello World!\n";" Someone help me please! Thanks in advance! [edit]Ok thanks Sneftel! I'll add the code now![/edit] Newbie Game Developer! [edited by - b0iNg on March 18, 2003 1:09:06 AM]
Newbie Game Developer!
Advertisement
"Or something" is the wrong way to get help. Post the exact error message, and the exact code you were compiling.

How appropriate. You fight like a cow.
Dev-C++ works fine with either C or C++.
That said, here's what you should do:
Instead if including iostream.h, include iostream (note: without ".h")

then, after your includes, put: using namespace std;
Which gives

    #include <iostream>using namespace std;int main(){cout << "Hello World" << endl;return 0;}    


That should work.


[edited by - rizman on March 18, 2003 5:46:23 AM]
nota bene: there should be a line break between the #include line and the using line. GameDev''s forums are buggy, and take it out. Be warned.

How appropriate. You fight like a cow.
Thanks for those advices! However why does the coding look different from those in the tutorial I''m reading? That is kinda weird..

Like for example:
"cout << "Hello World!\n";"

is in the tutorial and the tutorial is meant to teach me C++

while the coding you gave me:
"cout << "Hello World" << endl;"

is different and it is suppose to be c++!

That is very confusing..should I continue using that guide? Can someone please tell me if that tutorial is actually correct/reliable or does it actually has errors? (Or maybe dev-c++ has some problem with that kind of coding?)

Thank you in advance..please don''t mind my ignorance..I''m still a newbie
Newbie Game Developer!
The book is reliable yes.

"\n" and "endl" do the same thing, they tell the program to put the cursor on the next line.
"\n" is the same as "endl". When programming pure C++, most people will use "endl". "\n" is what you used in C (though it can still be used in C++). I will give you the Hello World Programm in pure C, so you can compare:


  #inclue <stdio.h>int main(int argc, char **argv){printf("Hello World\n");return 0;}  


This should give the exact same result as the C++ counterpart.

If you have any other question, don''t be afraid to ask. We were all newbies once. (I am myself still a newbie).
quote:Original post by deathtrap
"\n" and "endl" do the same thing, they tell the program to put the cursor on the next line.

Well, almost - they both do that, but endl also flushes the output buffer. If you never use endl (or flush, or cin::operator>> which also flushes the buffer, etc.), you''re not guaranteed that your output will actually appear prior to the termination of the program ...
Well Mr "Miserable", after reading what you said, it really made me miserable

Thanks RizMan for the example code!

So does that mean my code will look like this:


  #inlude <iostream>using namespace std;int main(){cout << "Hello World!" << end1;return 0}  


Right? Btw, is it must to include the "using namespace std;" part?
Newbie Game Developer!
quote:Original post by b0iNg
Right? Btw, is it must to include the "using namespace std;" part?

Not really - in fact, many people consider it poor programming practice to do it at all (in the global scope). However, I''m fairly sure that you''ll have learned why long before it becomes relevant. Just make sure to put it on its own line.

This topic is closed to new replies.

Advertisement