Below is the C plus plus source code to remove special characters other than alphabets (excluding upper and lower case letters).
// C++ source code to remove special characters other than alphabets from a string #include <iostream> using namespace std; int main() { string str; cout << "Enter a string with special characters: "; // Read the entered string getline(cin, str); // remove special characters from the string for(int i = 0; i < str.size(); ++i) { if (!((str[i] >= 'a' && str[i]<='z') || (str[i] >= 'A' && str[i]<='Z'))) { str[i] = '\0'; } } // Print the result cout << "Output String after removing special characters is: " << str; return 0; }
Output:
C plus plus code output for removing special characters from string
Check C plus plus code to Extract String between two delimeters