Your compiler is new enough, you should be using the string class rather than C-style strings. That would sidestep the problem you're having entirely:
#include <string>
std::string key;
std::string msg;
std::cout<<"Enter the key: ";
if (!std::getline(std::cin, key)) {
// Handle input error
}
std::cout<<"Enter the message: ";
if (!std::getline(std::cin, msg)) {
// Handle the error
}
The problem you're having is identical to what you would see in C with fgets. The first call reads n-1 characters and returns without extracting a newline character, the second call read everything that was left. The effect is that it looks like the second call for input is skipped. The solution is also identical to what you would do in C (assuming you don't want to use the string class).
>use the 32bit (4byte) pieces of the message and key for binary operations
What binary operations are you planning on using?
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004