Archived

This topic is now archived and is closed to further replies.

b0iNg

Lots and lots of help needed here!

Recommended Posts

b0iNg    122
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]

Share this post


Link to post
Share on other sites
Sneftel    1788
"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.

Share this post


Link to post
Share on other sites
RizMan    146
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]

Share this post


Link to post
Share on other sites
Sneftel    1788
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.

Share this post


Link to post
Share on other sites
b0iNg    122
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

Share this post


Link to post
Share on other sites
RizMan    146
"\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).

Share this post


Link to post
Share on other sites
Miserable    606
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 ...

Share this post


Link to post
Share on other sites
b0iNg    122
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?

Share this post


Link to post
Share on other sites
Miserable    606
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.

Share this post


Link to post
Share on other sites
Dobbs    164
Also Miserable is technically right - you don't have to have the line "using namespace std;" - but he forgot to mention that if you don't do it you have to put "std::" in front of "cout" and "endl" in your code instead.

If you have a book about C++ or can find a good tutorial online, read about namespaces. That will explain the reason behind all this.

Edit: I really need to do something about my posting diarrhea

[edited by - Dobbs on March 18, 2003 1:39:04 PM]

Share this post


Link to post
Share on other sites
b0iNg    122
Erm guys..I dont know what I am doing wrong! I am receiving alot of errors when I compile! I dont know what kinda of errors it is. If someone can really help me, please drop me an email at jeff_lam10@hotmail.com

I have MSN, best if you have it too. I took a screenshot of the errors as it really is difficult to explain. If you can help me I''ll send you the screenshot.

In fact it shows that I have 70 errors! What the hell!? Argh...

Share this post


Link to post
Share on other sites
b0iNg    122
I just found out that alot of the problems seem to be caused by ! In fact when my code is:


  
#include

using namespace std;

int main();

{
cout << "Hello World!" << endl;
return 0;
}


I only get 2 errors. First error is about the missing file that should be in front of #include. 2nd error is an error I dont quite understand - its an error of the first curly bracket, saying that it is a parse error? I dont understand. I got the screenshot though, so someone please try to contact me!

[edited by - b0iNg on March 19, 2003 9:00:29 AM]

Share this post


Link to post
Share on other sites
b0iNg    122
I just found out that no matter what, anything I compile seem to have a problem. Even the examples provided by Dev-C++..I open the project and compile it and it still has errors. So what does this mean?!?

Share this post


Link to post
Share on other sites
Dobbs    164
After #include you should have a file name, in this case iostream. Like this:


  
#include <iostream>

using namespace std;

// etc.

Share this post


Link to post
Share on other sites
smart_idiot    1298
quote:
Original post by b0iNg
I just found out that no matter what, anything I compile seem to have a problem. Even the examples provided by Dev-C++..I open the project and compile it and it still has errors. So what does this mean?!?



Are you using the newest version with GCC 3.2? If so, go to the Compiler Options, go to Directory Settings, select C++ Includes, and in the space provided at the bottom, write C:\Dev-Cpp\include\c++\mingw32 (if you didn''t install to the default location change it to reflect that) and click on Add.

Share this post


Link to post
Share on other sites