void decryption() //this function decrypts whatever the user inputs using keys 1 - 100, providing all possible decryptions
{
const int MAX = 100;
string code, output;
char array[100];
cout << "Enter what you would like decrypted" << endl;
cin >> code; //herein lies the problem
strcpy(array, code.c_str());
for (int key = 0; key <= 100; key++)
{
for (int i = 0; i <= strlen(code.c_str()); i++)
{
if (array[i] - key < 32)
output += ((array[i] - key) + 127) - 32;
else
output += (array[i] - key);
}
cout << "Output using key " << key << ": " << output << endl;
output.erase();
}
getchar();
getchar();
exit(1);
}
This is my code so far, it all works fine except that the cin >> code takes in the '\n' newline character when I dont want it to.
I've tried using
cin.ignore(1000, '\n');
getline (cin, code);
to get around the problem but it does the same thing as the cin >> code;
What can I do to fix this?
Thank you.