Im trying to write a program that simply takes a string input and reverses it. I want the program to repeat itself by asking the user then starting over. The problem im having is that when the program first runs, the getline function works correctly but then after the program repeats itself it seems to skip the getline. Any ideas to why this is? The code is below...thanks for all replys!
#include <iostream>
#include <string>
using namespace std;
void swap(char &p1, char &p2);
int main(){
char repeat = 'y';
while (repeat == 'y'){
string line;
char *p1, *p2;
cout << "Enter a line\n";
cin.ignore(cin.rdbuf()->in_avail(),'\n');
getline(cin, line);
p1 = &line[0];
p2 = &line[(line.length()-1)];
for (int i = 0; i<(line.length()/2);i++){
swap(*p1, *p2);
p1 = p1+1;
p2 = p2-1;}
cout << line << endl;
cout << "Do you want to repeat? (y/n) \n";
cin >> repeat;}}
void swap(char &p1, char &p2){
char temp = p1;
p1 = p2;
p2 = temp;}