C++ check if Palindrome
Advice 1: getting the job done the C++ way

You can check whether the input string is a palindrome in one line:

bool is_palindrome(std::string&amp; text) {
    return std::equal(text.cbegin(), text.cend(), text.rbegin());
}


For Incomputable has spoken: You can make the above run in the worst case faster by the factor of two:

bool is_palindrome(std::string&amp; text) {
    return std::equal(text.cbegin(),
                      std::prev(text.cend(), text.length() / 2),
                      text.rbegin());
}


For Deduplicator has spoken: In is_palindrome, change std::string&amp; to std::string const&amp;; this will guarantee that the input string is not modified.

Advice 2

Whatever you implementation of the palindrome checker is, have a dedicated method that does not output the result to std::cout, but rather returns a boolean indicating whether the input string is a palindrome or not.

Advice 3

void main() does not compile on modern Xcode; change to int main().

Advice 4

Please avoid

using namespace std;


since it pollutes your namespace by importing quite a lot of identifiers/type names.

Advice 5

cout &lt;&lt; "Your string is: "; cout &lt;&lt; str &lt;&lt; endl;


You can write:

cout &lt;&lt; "Your string is: " &lt;&lt; str &lt;&lt; endl;


Alternative implementation

I had this in mind:

#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

bool is_palindrome(std::string&amp; text) {
    return std::equal(text.cbegin(), text.cend(), text.rbegin());
}

using std::cin;
using std::cout;
using std::getline;
using std::string;

int main()
{
    string str;
    cout &lt;&lt; "Enter a string: ";
    getline(cin, str);
    cout &lt;&lt; "Your string is: " &lt;&lt; str &lt;&lt; "\n";
    cout &lt;&lt; "Palindrome: " &lt;&lt; std::boolalpha &lt;&lt; is_palindrome(str) &lt;&lt; "\n";
}