By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,374 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,374 IT Pros & Developers. It's quick & easy.

some error in a program

P: 51
Hi!!!!!!!, I want to read two strings that the user must enter, and i am doing it this way:

cout << "Please enter the text that you want to Encrypt (128 bits legth)" << endl;
getline (cin, a);

length1 = a.size();

cout << "Please enter the key to Encrypt the text (128 bits legth and Hex format)" << endl;
getline (cin, b);
length2 = b.size();

and I have a problem, because I don't why this program does not read the second one, could you please tell me how can I read the two strings (the problem is that the instruction getline (cin, b);, does not execute). Thank you
Sep 18 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 144
Hi!!!!!!!, I want to read two strings that the user must enter, and i am doing it this way:

cout << "Please enter the text that you want to Encrypt (128 bits legth)" << endl;
getline (cin, a);

length1 = a.size();

cout << "Please enter the key to Encrypt the text (128 bits legth and Hex format)" << endl;
getline (cin, b);
length2 = b.size();

and I have a problem, because I don't why this program does not read the second one, could you please tell me how can I read the two strings (the problem is that the instruction getline (cin, b);, does not execute). Thank you
Often times the cout buffer is not flushed completly. Try adding a "cout.flush()" after each cout statement.

Expand|Select|Wrap|Line Numbers
  1.  
  2. cout << "Please enter the ..." << endl;
  3. cout.flush();
  4. getline(cin, some_variable);
  5.  
  6.  
Sep 18 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.