c++ Pause Command for Linux Terminal

Mar 21, 2011 at 2:01pm
Hi

I want to pause my program in Linux Terminal. But i can't.

i Have tried many commands, Like
system("pause");
sleep(100);
usleep(10);
getchar();
cin.get();

No one is working on linux terminal.
Please help me.

Thnx in advance
Last edited on Mar 21, 2011 at 2:01pm
Mar 21, 2011 at 2:45pm
cout<<"Press ENTER to exit";
cin.ignore(cin.rdbuf()->in_avail()+1);

But srsly, either start the program from the console, or start it from the IDE. A program that asks for user input before termination is not very user friendly (ex: You could direct cout and cin to files - in that case, it would be very stupid to ask for further user input)
Mar 21, 2011 at 3:02pm
You can use "read" but this should only be a temporary solution.
Mar 21, 2011 at 3:37pm
Hanst this code is not working
cout<<"Press ENTER to exit";
cin.ignore(cin.rdbuf()->in_avail()+1);


and i am not able to use the "read" command please specify the command.
Mar 21, 2011 at 5:59pm
That code works perfectly fine for me. Anyways, what you should really do is just ignore the pause part and launch the program from the terminal. Terminal applications are expected to be run from the terminal.
Mar 22, 2011 at 7:44am
ya i am able to run the program. but i want to pause the program at the end of the program.

but i can't pause................... anyone can tell me.
Mar 22, 2011 at 8:37am
i did it by this command.
You can also try .
Thnx for help

Pause Command

#include <iostream>
using namespace std;

int main()
{
cout << "Enter to exit the program: ";

cin.ignore().get(); //Pause Command for Linux Terminal

return 0;
}
Mar 22, 2011 at 11:30am
The "command" depends entirely on linux terminal type, there are many of them and no standard ones like windows built-in cmd.exe when everybody know what to do.
Mar 22, 2011 at 6:36pm
The question is, WHY do you WANT to pause? it doesn't even make any sense to do that.
Mar 23, 2011 at 12:17pm
i just want to know the command.
nothing more.........

now i can pause in Ubuntu terminal...... ;)
Topic archived. No new replies allowed.