Skip to main content
GameDev.net gamedev.net
🔒 Locked

Code error

Started by mecrazy Apr 10, 2005 at 7:21 PM 7 replies 1.1k views
Original Post
mecrazy
mecrazy
Hey every1 iv run into a bit of trouble with my first code and need a bit of help. i downloaded dev-c++ started learning out of a book called "accelerated c++". and typed in the hello world code - #include int main() { std::cout<<"hello, world!"<<std::end1; return 0; } and it says the following errors occured in function 'int main()': 'end1' is not a member of 'std' [Build error][project1.o]Error 1 could you please explain where my code has gone wrong.
Accelerated C++
Drew_Benton
Drew_Benton
It is supposed to be std::endl. It's a lowercase 'L' at the end, not a 1. Yea, it's tricky in those books [wink].
mecrazy
mecrazy
HAHA!. thanks mate i swear it looks like a 1 but lol
Accelerated C++
gcsaba2
gcsaba2
In Dev-C++ go to New->Project and chose Console project. That'll make you a Hello world application [wink]

Also, it is a lot better if you write "using namespace std" at the begining of your application, so you wouldn't have to write std::cout and stuff, only cout
Drew_Benton
Drew_Benton
Quote:
Original post by gcsaba2
Also, it is a lot better if you write "using namespace std" at the begining of your application, so you wouldn't have to write std::cout and stuff, only cout


Oh no, I would strongly reccomend against that buddy [smile]
mecrazy
mecrazy
1 more thing when i run the program the dos window opens up with "hello world" in it but then imediatley closes. how do i stop this?
Accelerated C++
Drew_Benton
Drew_Benton
Add a system("pause"); at the very end before it returns. Dev-CPP does this automatically with their default Console projects. Go ahead and give that a try as well. Go to file New->Project and select for it to be a console. It will give you a basic enample to work with as well. Good luck learning C++!
mecrazy
mecrazy
thanks for your help guys.
Accelerated C++
Zahlman
Zahlman
Quote:
Original post by Drew_Benton
Add a system("pause"); at the very end before it returns. Dev-CPP does this automatically with their default Console projects. Go ahead and give that a try as well. Go to file New->Project and select for it to be a console. It will give you a basic enample to work with as well. Good luck learning C++!


To be more accurate, Dev-CPP invokes the "pause" command on your system after running your program.* Relying on system("pause") - or the system command in general - is not such a good idea; it basically behaves as if that input argument were typed on the command line, or in a batch file - which is where commands of that sort should go.

For console apps, the best solution is generally "don't worry about it in your program; make a wrapper instead". This way, you avoid one source of platform dependence in the app, avoid having Dev-CPP "pause" twice at the end* (a minor annoyance while testing), and Use the Right Tool for the Job(TM). Specifically, suppose you have "mygame.exe"; in the same directory, you would make a text file containing the following:
mygame.exepause

and rename it as "mygame.bat" or something like that. Then double-click the batch file in Windows to run the program (and invoke the pause at the end).


Also, using namespace std; is fine in your source file. You should not use it in header files, however.


* Er, I think that's what was meant. I don't actually have Dev-CPP. The other possibility is that it gives you a template for a source file with system("pause"); filled in at the end of main(). If that's the case, then ignore my ranting here - and apologies to Drew - but many harsh words for the Dev-CPP people [wink]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.