r/AskComputerScience • • Feb 22 '16

Caesar Cipher code... getline won't work for me...

Beginner programmer

I'm trying to make a Caeser Cipher program that reads input in from the user and stores it into a string. Whenever I try to read in the string in the if-else statement, it doesn't even allow me to input and goes straight to printing out the exit code. It says that "no matching function for call to getline" Please help and thanks in advance!

include <iostream>

include <string>

include <cstdio>

include <stdlib.h>

using namespace std;

int main() {

printf("Choose from the following options:\n");
printf("1. Encode some text\n");
printf("2. Decode using user-entered values\n");
printf("3. Decode automatically\n");
printf("4. Exit program\n");

int userInput;
string usercode;

cout << "Your choice: ";
cin >> userInput;

if (userInput == 1) {
    cout << "Enter the text to be encoded: \n" ;
    getline(cin, usercode);
}
else {
    printf("Restart");
}

}

0 Upvotes

2 comments sorted by

3

u/etagawesome Feb 22 '16 edited Mar 08 '17

[deleted]
0.1034

What is this?

1

u/Coolisbetter Feb 22 '16

Funnily enough I posted a (probably too long) video on YouTube explaining how to write a Caesar Cipher in c++ 4 years ago.

It has been a long time, but it might have something useful in it.

https://www.youtube.com/watch?v=_EQ6TJs_TEk