I am solving one DSA question I want extract character only to check whether given sentence is Palindrome or not, so I want to remove spaces and other punctuations following code is useful for it.
string str1;
for(char c : str)
{
if(isalnum(c))
{
str1+=tolower(c);
}
}