cin >> and cin.get( ) not pausing program?

For some reason, the exertion operator and get( ) don't cause the DOS to wait for a return. Here is my main function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main( int argc, char* argv[] ){

	cout << "Enter some text to be encrypted:" << endl;
	char* str = new char[50], *key = new char[50];

	cin >> str;
	cout << endl << "Enter an encryption key:" << endl;

	cin >> str;
	cout << endl << "\nEncrypted: " << encrypt ( str, key );

	cin.get( );

	delete [] str;
	delete [] key;

	return 0;
}


Any suggestions?
Last edited on
Put an std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); before the cin.get();.
Last edited on
What will that do? And what am I supposed to include for it? I included iostream and cstdio, but I'm getting errors.
Last edited on
It will discard all characters up to and including the first '\n' in the buffer.

Also read:
http://cplusplus.com/forum/articles/6046/
Works like a charm, thanks.
I'm working on this exact code.
Are you reading c++ without fear?
Not exact, but similar...
Last edited on
I read C++ for dummies. Not my best choice, but it taught me plenty of what I needed to know.
Put an std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); before the cin.get();.


Put chrisname' code after every cin>> statement.
And what do I have to include for that? Regular iostream doesn't have it.
And what do I have to include for that? Regular iostream doesn't have it.
<limits>
Heh, had a feeling.
Sorry :P

I forgot to add "#include <limits"

:(
Topic archived. No new replies allowed.