| View previous topic :: View next topic |
| Author |
Message |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Thu Jan 31, 2008 5:10 pm Post subject: |
|
|
Omg.. lol.
thanks HolyBlah for reminding me of an old method in particular and the others who helped me in solving this issue .
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Thu Jan 31, 2008 6:19 pm Post subject: |
|
|
| iCucco wrote: | | SirSteez wrote: | haha alright thanks guys i'll try those.
where would i insert those in
| Code: |
#include <iostream>
int main();
int main()
{
std::cout << "Hello World!\n";
return 0;
}
|
and is having both the "int main()"'s necessary?
I tried putting in the Sleep(INFINITE); right after return 0; and that didn't work.
I also tried guernica's method after the } and also tried replacing it with the current return 0;, neither worked.
In cmd prompt I went to the .exe's destination folder and tried running the program there but it said "'hello world.exe' wasn't recognized as an internal or external command or as an operable program or batch file.
although i found out keeping cmd prompt open isn't really necessary, for my compiler shows what the program does below the source.. >_< |
It doesn't work because is the exit call for the main thread. If you put code after that call, it will not be executed. Put it this way: | Code: | | Sleep(INFINITE); return 0; |
Although it's not necessary to put in "return 0;" if you are planning to use Sleep(INFINITE) it's better to be sure that your program is terminated if something unusual happens.
As for the code: | Code: |
#include <iostream>
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
using namespace std;
int main()
{
cout << "Hello World!"<<endl;
Sleep(INFINITE);
return 0;
} |
@Wiccaan: You're absolutely right, system("pause"); is awful way of stopping the application, but it is a method to do that anyways. |
Dear god don't use something like Sleep( infinite ); just to have a program pause... there is absolutely no reason for you to do that.. You are already using iostream and the std namespace, just use the cin features to pause the program..
| Code: |
std::cin.ignore();
std::cin.sync(); |
Or as x0r pointed out, you can also use _getch() which is defined in conio.h.
_________________
- Retired. |
|
| Back to top |
|
 |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Sun Feb 03, 2008 1:18 pm Post subject: |
|
|
| thanks for the help everyone =)
|
|
| Back to top |
|
 |
|