-
Window Wont Stay Open
I use the latest version of Dev C++, with the following code:
Code:
#include <iostream.h>
int main()
{
char response[25];
cout << "Hello World";
cin >> response;
cout << "Oh thats nice";
return 0;
}
And when this executes it'll wait for my input and then immediatly close, without displaying "Oh thats nice". How do I stop the window from closing?
-
Hello wes welcome to the boards heres a link that will answer all your questions
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
-
:D I can't believe I missed that in the FAQ!
Well, this does the same thing, and it exits early:
Code:
#include <stdio.h>
#include <iostream.h>
int main(void)
{
int ch;
char response[25];
cout << "What's up?";
cin >> response;
cout << "That's cool...";
printf ("Press [Enter] to continue");
while ((ch = getchar()) != '\n' && ch != EOF);
return(0);
}
What's wrong? Thanks for the help :)
-
Because your cin is leaving a newline in the input stream btw: i would use this instead considering your using c++ :)
Code:
#include <iostream>
using std::cout;
using std::cin;
int main(void)
{
char response[25];
cout << "What's up?";
cin >> response;
cout << "That's cool...";
cin.ignore(80,'\n');//so that it will stop at the end of the program
cout<<"Press [Enter] to continue";
cin.get();//this will wait for a key press
return 0;
}
-
I'm such a newbie :p
Thanks guys.