![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
return 0; not working in c++ in visual studio 2005?
Everytime I put the return 0; command that you have to for apps like 'hello world' so that you need to press enter before the app closes doesnt work using visual studio 2005.
can someone help me? |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3
![]() |
return 0; doesnt make the program wait. Although in VS, if you don't run in debug mode, it should pause on its own (using Ctrl-F5). Otherwise, look here.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
Thanks for the link, I'll try that when I can get back on the computer with the compiler
![]() Umm, I dont understand why return 0; isnt working anymore, I remember I had compiled a 'hello world' app sometime ago with another c++ compiler and it worked, is this a general change to how c++ works? |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
As Jimbo said, return 0; does not make the programme wait. On the contrary, it returns the value 0 to the calling function/programme and in this case, it closes the programme.
If you want it to wait, add something like: #include <iostream>
int main()
{
// code
std::cin.sync();
std::cin.get();
return 0;
} |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Feb 2006
Posts: 20
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Feb 2006
Location: UK
Posts: 36
Rep Power: 0
![]() |
You should learn what return 0 actually means. I know in Java System.exit(0) means that the program completed correctly and System.exit(1) (C++ equiv of return 1; at the end of main) means there is an error, but depending on how you work returning 0 and 1 could mean correct execution or error in the program.
That was probably rather unclear, someone else (who has more experience of C/C++) feel free to clarify. One more thing, why do people use the M$ products Vis Stuido n so on, is it because its easy to make GUIs like in Delphi or just don't they care about the non-portability and so on of their code? ![]() |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
.TD, you can code portably in Visual Studio - you just can't use .NET (well, you can, but the Mono project doesn't support everything yet).
Generally, in most OSes, returning an exit code of 0 means the program executed successfully - anything else is an error code. return 0; has nothing to do with making your program wait - it simply tells the operating system your program is exiting with an exit code of 0. As UnKnown X said, use std::cin.get() to request input and stall the exiting. |
|
|
|
|
|
#8 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#9 | |
|
Programmer
Join Date: Mar 2006
Location: Tennessee
Posts: 41
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
wtf???
my first problem with vs 2005 was the precompiled header stdafx.h being automatically included in all win32 console projects. figured it out...yay. it automatically inserts a system("pause") (or something that acts just like it after your code)...i don't understand what you mean. but if it's not...just do the cin.get() deal and it'll be fine.
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|