So im in the middle of trying to teach myself c++ by reading C++ Primer the fourth edition, and im stuck on one of the exercises and could use some pointers to sort it out. If possible please dont just give the answer to the problem just tips on figuring it out would work thank you.
Exercise - Write a program to strip the punctuation from a string. The input to the the program should be a string ofcharacter including punctuation; the output should be a string in which the punctuation is removed.
This is what I have so far and where im stuck, if you see anything else out of place or misused let me know.
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
string s1;
getline(cin, s1);
for(string::size_type index = 0; index != s1.size(); ++index)
if (ispunct(s1[index]))
// This is where im stuck
// Dont know how to delete the punctuation
cout << s1 << endl;
return 0;
}
Thanks guys for the help for the s1.erase(index, 1). The way im guessing it works is index is where it starts the delete and 1 means it deletes one char? Thats what I got from it let me know if im wrong.