When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
22 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
!format
int main() {
// Main message:
cout << "1. Encrypt message" << endl;
cout << "2. Decrypt message" << endl;
cout << "3. Show decrypted possibilities" << endl;
cout << "4. Break code" << endl;
cout << "Enter choice: ";
int choice, shift, direction;
string messege, encriptedMessege;
cin >> choice;
switch (choice) {
case 1: {
cout << "Enter shift (1-26): ";
cin >> shift;
cout << "Enter direction (f or b): ";
cin >> direction;
cin.ignore();
cout << "Enter message: ";
getline(cin, messege);
encriptedMessege = encryptMessege(messege, shift, direction);
cout << "Encrypted message: " << encriptedMessege;
break;
}
}
}
!code
```cpp
int main() {}
```
int main() {}
Why do you have the cin.ignore() without arguments?
You’re close to solving the problem of getline getting skipped
I didn't know it needed arguments
Do you know what the function does?
does it get rid of whitespace? im pretty sure thats my issue but i cant figure out how to fix it
the suggestions ive seen was use cin.ignore or use getline twice but neither worked for me
It gets rid of more than just white spaces. It takes the size of the characters you mentioned or till it reaches a delimiter in the input stream and discards them.
A
By the curly bracket I mean the case 1: {} should just be case 1: \statements then break after the statements
ok i got rid of the brackets and i tried cin.ignore(numeric_limits<streamsize>::max(), '\n') and it still wont read any input
it just skips it completely
Move the cin.ignore(numeric_limits<streamsize>::max(), '\n'); right before the getline statement and compile it again
ok yes it works now thank you
Nice
I found this from stackoverflow and I think it describes it better than I did. “for std::cin statements you use ignore before you do a getline call, because when a user inputs something with std::cin, they hit enter and a '\n' char gets into the cin buffer. Then if you use getline, it gets the newline char instead of the string you want.”
@shell scaffold Has your question been resolved? If so, type !solved :)
@shell scaffold
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.