Is there any "break" alternative to system pause other than getch

I need some breaks in my program, but I can't use getch or getchar because there is a lot of getline(cin, variable) in the code I'm writing. I don't want to have to resort to system("pause")
What's wrong with that?
With what? system("pause")? Apparently it opens the cmd just to stop your program, then runs it, then closes cmd to resume your program. Very resource heavy.
I'm sorry, I mean using getchar because there is a lot of getline.

Yes, you're right about system calls, I agree on that.
Last edited on
closed account (3bfGNwbp)
Not to mention system calls leave huge security gaps in your program.
but I can't use getch or getchar because there is a lot of getline(cin, variable)

Because you have a '\n' in your buffer. Try ignore():
1
2
3
4
5
6
7
8
9
string line;
getline(cin, line);  // getline extracts until it hits the delimiter, which defaults to '\n'
                     // getline(istream& in, string line, char delim = '\n')
cin.ignore(); // ignore(streamsize (an integer) amount, char delim = EOF)

cout << "You typed: " << line << endl;

// without ignore(), the get() returns the '\n' remaining from the getline()
cin.get(); // which is a C++ getchar() 
Last edited on
Topic archived. No new replies allowed.