•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,369 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1219 | Replies: 12
![]() |
The problem is (not really a problem), that the program is running too fast and doesn't have anything to stop it from closing. There are a number of options to solve this, most of them are mentioned here -- http://faq.cprogramming.com/cgi-bin/...&id=1043284385 so if you're using C++ throw a
cin.ignore(); and cin.get(); before you return 0; at the end of your program •
•
Join Date: Jan 2008
Posts: 55
Reputation:
Rep Power: 1
Solved Threads: 2
here at home i'm using dev c++ and i do get the same "problem"
i use system("pause") which i think is not preferred by others,but it's just me using it to see the output
then i just remove it when i'm at school because there we use visual c++
OR
run the program with the command prompt
i use system("pause") which i think is not preferred by others,but it's just me using it to see the output
then i just remove it when i'm at school because there we use visual c++
OR
run the program with the command prompt
Last edited by carnage : Feb 2nd, 2008 at 8:00 am.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
Don't use
Both are non-portable.
Instead, do it the C++ way:
Now if you want to pause, just use the function:
Hope this helps.
- getch()
- system("PAUSE")
Both are non-portable.
Instead, do it the C++ way:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <limits> void pause() { std::cout << "Press ENTER to continue... "; std::cin.ignore( std::numeric_limits<streamsize>::max(), '\n' ); }
Now if you want to pause, just use the function:
C++ Syntax (Toggle Plain Text)
int main() { using namespace std; string name, color; cout << "WHAT, is your NAME!?\n"; getline( cin, name ); cout << "WHAT, is your favorite COLOR!?\n"; getline( cin, color ); cout << "Aaaiiiiiieeeee!\n"; pause(); }
Hope this helps.
Last edited by Duoas : Feb 2nd, 2008 at 1:58 pm.
Non portable means that the code won't work on all systems -- suppose you were to compile on one system it might work but that doesn't mean it will compile on all systems. Using system is a bad idea for pausing. getch() is a lazy excuse. Duoas' solution is good. Use that.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: Is a variant return type possible in C++?
- Next Thread: help



Linear Mode