![]() |
|
#1
|
|||
|
|||
App wont stay opencan anyone tell me why my proggy will not stay open,
CPP / C++ / C Code:
thanks |
|
#2
|
|||
|
|||
Re: App wont stay openYou can't be serious! This is probably the third, at least the second, thread where you ask the EXACTLY same thing. Unless you start these out just for the fun of it, check out your previous threads for some answers.
|
|
#3
|
|||
|
|||
Re: App wont stay openive tried what you previously suggested and ive added it in this code and what your suggested is a load of old coblers, try and complie it.
|
|
#4
|
|||
|
|||
Re: App wont stay openAll I have been suggesting is to use
CPP / C++ / C Code:
EDIT I don't mean to be rude, but I haven't seen you actually getting back to threads you have started. There's no sign that you actually have taken heed of the advice given or tested out the stuff shown in the previous threads. The picture I'm slowly getting is that you start threads, maybe look at the responses, maybe test out the code and see it works, but then when you encounter basically exactly the same situation in another context, you don't want to go back to the old threads to look for advice. Instead you start a new one. If there's something wrong with the advice people give here, tell them so! If it just doesn't work, tell so! Walking away without a word and starting new threads really doesn't help anyone, since you're basically getting the same responses to the same problems over and over again. Last edited by Kimmo : 02-Aug-2007 at 15:25.
|
|
#5
|
|||
|
|||
Re: App wont stay openQuote:
There are actually two problems: CPP / C++ / C Code:
However, when you fix that (by declaring char question5; instead of int question5; you still have the same action: It doesn't wait before closing. Here is why: When a C++ program gets something from stdin (with cin >> or with cin.get(), for example) here is what happens: As the user presses keys, the characters are stored in a system buffer (somewhere outside your program's data space) until the user presses 'Enter'. Nothing is available to any program functions until the user presses 'Enter'. After the user presses 'Enter', the characters are available to the program input functions. All of the charactes are now in the system buffer and a newline character ('\n') is at the end. Consider the following: CPP / C++ / C Code:
Suppose the user presses the 'y' key and 'Enter'. So the buffer contains two chars: 'y' and '\n' Now cin >> question5 removes the character 'y' from the systembuffer and sets question5 equal to this value. The '\n' is still in the system buffer. Later, you do cin.get() and it retrieves the '\n' that was left in the buffer, and the program exits. A quick fix (but not necessarily the best thing to do from the point of view of future requiremenes) is just to put another cin.get(): CPP / C++ / C Code:
Regards, Dave Footnote: After testing the above program, let me know if it doesn't work as it should. Then and only then, go back and change question5 to an int, as it was in your original program. You will find that it will not wait for any more input on cin, no matter how many cin.get() statements you add. When cin is in the "fail" state, it can't do anything. |
|
#6
|
|||
|
|||
Re: App wont stay openthanks for the advice kimmo
|
|
#7
|
|||
|
|||
Re: App wont stay openthanks dave, the best answer ive got so far, but i added in
CPP / C++ / C Code:
under which is ment to clear the buffer, but sill have the same problem, is there anyother way to clear the buffer. Thanks |
|
#8
|
|||
|
|||
Re: App wont stay opendosent matter i added this under in the case y and case n blocks and it worked. Thanks for your help
|
|
#9
|
|||
|
|||
Re: App wont stay openQuote:
I like that much better, since it removes not only the next char, but lots more (In case the user entered "yes" instead of "y" for example.) I was just trying to keep it simple with my "quick fix". Note that cin.ignore() only works if cin is not in the "fail" state, so a more complete solution, in general, might be CPP / C++ / C Code:
The clear() would not be needed if you had only used cin for chars. It might be necessary if you had numeric input failures (trying to read an int but the user entered alphabetic chars, for example). Quote:
Regards, Dave |
|
#10
|
|||
|
|||
Re: App wont stay openI began playing around and ran into the following problem.
I want to display lines of text a certain amount of lines at a time. After that certain amount of lines shown, I of course want the user to have time to read the text. The user presses Enter when he wants the next lines shown. For example, if I use the following: CPP / C++ / C Code:
Now if I use something like this: CPP / C++ / C Code:
I tried to think but couldn't come up with a nice solution. I can't use cin.peek() because it waits for input too, if there is none. I thought maybe there is some way of determining if there is input pending for the program. But didn't find any (or just didn't understand. ios_base can be hard to get for us newbies). So what's the simple solution I just fail to see here? |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Console Will Not Stay Open | doom1992 | C++ Forum | 15 | 16-Aug-2007 07:26 |
| open google search from a vb program | isnoend07 | AdSense Forum | 0 | 23-Jul-2007 17:48 |
| Apache default page can't be visited | satimis | Apache Web Server Forum | 0 | 05-Apr-2007 05:40 |
| [ANN] New script engine: Open Basic (Basic syntax) | MKTMK | Computer Programming Advertisements & Offers | 0 | 01-Sep-2005 07:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The