Game Over

May 10, 2013 at 6:22pm
Im New To C++ And When I Open The File The Window Just Opens And Closes. Ive Been Told To use pause but i dont know where to use it in my code HELP

#include<iostream>

int main()
{
std::cout <<"Game Over!"<<std::endl;
return 0;

}

Last edited on May 10, 2013 at 6:26pm
May 10, 2013 at 6:26pm
Write it like this :

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <windows.h>

int main()
{
    std::cout <<"Game Over!"<<std::endl;
    system("pause");
    return 0;
}
Last edited on May 10, 2013 at 6:27pm
May 10, 2013 at 6:39pm
no don't use system("pause")
use something like cin.get(); cin.clear(); cin.ignore();

ps it is a sticky topic at the very top probably should of read first =p.

http://cplusplus.com/forum/beginner/1988/
May 10, 2013 at 6:57pm
I agree with giblit but the only reason i wrote it is that he asked for it specifically .
May 10, 2013 at 7:14pm
@BaseRev

is windows.h really necessary? As far as I know std::system is a C++ function that communicates with the terminal at hand. I do not run windows, would you mind trying? I am interested? For me using xterm on Linux mint x64:

1
2
3
4
5
6
7
8
9
#include <cstdlib>
#include <iostream>

int main()
{
    std::cout << "We will not see this string for long!\n";
    std::system("clear");
    std::getchar();
}


clears correctly without including linux headers.
May 10, 2013 at 7:40pm
no you can't use std::sytem and I have never heard of it being part of the std class and when I am on linux I don't need to use std::system it's just system() and windows.h is required on windos for anything that uses the windows api I am pretty sure of
May 12, 2013 at 6:49am
@Bourgond

Yes,it is necessary. I don't know about Linux but on windows you must include "windows.h".
But I am curious though c++ STL is supposed to be standard so how can it has a function on Linux but not on windows ?


It worked. windows.h isn't necessary and you can use std::system on windows.Thanks for the new info !!
Last edited on May 12, 2013 at 7:26am
May 12, 2013 at 7:03am
BaseRev wrote:
Yes,it is necessary. I don't know about Linux but on windows you must include "windows.h".

Who says windows.h is necessary, windows.h may have additional namespace function that performs the same operation, but the standard library that embeds system() functions is the cstdlib.
BeastlyHex wrote:
Im New To C++ And When I Open The File The Window Just Opens And Closes. Ive Been Told To use pause but i dont know where to use it in my code HELP

Help has been on the first page ever since the opening of this website(who told me?), and its been the second post on the page, beautiful comments are there on how "efficiently" you can tackle that problem.
May 12, 2013 at 7:17am

Who says windows.h is necessary, windows.h may have additional namespace function that performs the same operation, but the standard library that embeds system() functions is the cstdlib.


Nice I didn't know that , but I don't actually use c-like functions much.
May 12, 2013 at 4:10pm
Ah sorry I never use cstdlib
Topic archived. No new replies allowed.