Hi i'm having trouble making a function that checks the data type of a variable and checks it to make sure if a data type is similar to it in C++. Here's my code so far:
#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
    int typeCheck(string words, string typeWanted);
    //make number assurance function        .
        string word;
        cin >> word;
        typeCheck(word, "string");
}
int typeCheck(string words, string typeWanted) {
    if (typeid(words).name() != typeid(typeWanted).name()) {
        cin.clear();
        cin.ignore();
        return 0;
    }
    else if (typeid(words).name()== typeid(typeWanted).name())
        cout << "All good";
}
When I run the code it keeps saying the same output which is: All good even if I put a string or an int when its not the correct one. Instead of saying this I want it to clear the buffer and ignore it. Can anyone help me with this problem? Thanks in advance!
 
    