Removing the punctutation in the string

PHOTO EMBED

Tue Dec 14 2021 11:17:42 GMT+0000 (Coordinated Universal Time)

Saved by @abzal_nurgazy #c++

#include <iostream>
#include <string>
using namespace std;
using std::string;



int main()
{	
	string str;
	cout << "Enter the string: " << endl;
	getline(cin, str);
	unsigned int len = str.size();  // intitilize len by its original size
	
	for (int i = 0; i < len ; i++) // keeps incrementing if there is no punctutation
	{
		if (ispunct(str[i]))
		{	
			str.erase(i, 1);   // erase the element i to one place.
			i--;   // new character takes place of the erased one. We are neglecting the effect of loop increment
			len = str.size(); // removing the punctutation shrinks the string size
		}						// length size changes with every iteration and we give new len value
	}
	
	cout << "The word without punctutation is " << str << endl;

	return 0;
}
content_copyCOPY