How to make string take in multiple words.

As of right now my code works with only one word not with a sentence. Thus I was wondering if there was some way to make my string continue take in letters/words even after spaces until they hit enter?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string a;
    string x;
    cout << "Enter string ";
    cin >> a;
    x = a;
    cout << a;
    reverse(a.begin(), a.end());
    if (a == x) {
        cout << "Is a palindrome" << endl;
    }
    else
        cout << "Not a palindrome\n";
}
Last edited on
Instead of using the extraction operator think about using getline(). The extraction operator stops processing the string when it encounters a whitespace character.

Cin.ignore();\\ used to ignore the spaces
getline(cin,a);
Sorry I would change then all for you, but I am on the go.
Last edited on
Topic archived. No new replies allowed.