Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Automatic Closing


ghost's Avatar
0 0

I need help with a problem that occurs when I try and make C++ applications. When I try to run any application in C++ it automatically closes within a split second. Even a simple 'Hello World' program will do that. To make it stop I always have to put in this statement: markupstd::cin.ignore(std::cin.rdbuf()->in_avail() + 2); Is there any way to make it so where I don't have to put in that statement? Don't flame please I just want to figure out why this is happening :|

Thanks, Kirk


ghost's Avatar
0 0

Post the entire code. Also, i'm guessing it's console, did you pause it?


ghost's Avatar
0 0

It is console. And sorry, I don't get what you mean by pause. But this is just an example. Even THIS closes automatically:

#include <iostream>
using namespace std;

int main()
{
       cout<<"This is stupid because this closes automatically!";
       return(0);
}

But when I put markupstd::cin.ignore(std::cin.rdbuf()->in_avail() + 2); it works fine and all I have to do is hit enter twice depending on how many times I have input in the program


ghost's Avatar
0 0

kirk_halo1994 wrote: It is console. And sorry, I don't get what you mean by pause. But this is just an example. Even THIS closes automatically:

#include <iostream>
using namespace std;

int main()
{
       std::cout<<"This is stupid because this closes automatically!";
       return(0);
}

system("pause"); Alright, this is how i would've wrote that:

#include <iostream.h>
using namespace std;

int main()
{
       cout << "This is stupid because this closes automatically!";
       system("pause");
       return 0;
}

ghost's Avatar
0 0

I'll try that out real quick hold on. Thanks for the help. :)

EDIT: It works but I have 3 books on C++, Practical C++ Programming 2nd Edition, C++ without fear, and C++ the core language but they all don't show that. But thanks a lot. You helped me out a ton because I hate trying to remember that statement :P


ghost's Avatar
0 0

Get "Learn C++ in 21 Days." The 21 days series are excellent resources.


ghost's Avatar
0 0

kirk_halo1994 wrote: I'll try that out real quick hold on. Thanks for the help. :)

EDIT: It works but I have 3 books on C++, Practical C++ Programming 2nd Edition, C++ without fear, and C++ the core language but they all don't show that. But thanks a lot. You helped me out a ton because I hate trying to remember that statement :P

hehe youve been to Cprogramming.net haven't you? I got those exact same books, what did you think of them?