Trying to Catch invalid symbols in a string

My question how I would check for invalid symbols in a string input from the user.
The way I have my code set up, I receive an input that includes commas and spaces(ex. dog, racecar, 23heijs) and a function parses the input into separate elements and places them into a vector. My issue is how to catch exceptions such as (&, *, #, etc.) and excludes characters, commas, spaces, and numbers(i don't want to lose my inputs). After passing an acceptable string, it will be parsed into a vector and another function will be implemented to mess around with the vector, etc. Below is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main(){
    Strings access;
    string input;

    try
    {
        cout << "Please type inputs (type quit to quit): " << endl;
        getline(cin, input);
        access.setVec(input);
    }
    catch()
    {

    }
    
    access.DisplaySizes(vec);
    cout << endl;
    access.DisplayVec(vec);
etc...


Thank you very much for considering my query. I hope to learn from your answers!
Hello, try using this to remove unwanted characters:
 
input.erase(std::remove(input.begin(), input.end(), ','), input.end());

http://www.cplusplus.com/reference/string/string/erase/
http://www.cplusplus.com/reference/algorithm/remove/
Last edited on
Topic archived. No new replies allowed.