c++ string

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

int main() { 

    char next;
    string message="All good!
";
    cin.get(next);

    while (cin.get(next) && (next != '
')) {
        if (! isdigit(next)) 
            message = "There's a non-number in here! 
";
    }
    cout << message << endl;

    return 0; 
}



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

int main() { 

    char next;
    string setofnums = "0123456789";
    string email;
    cin >> email;

    if (email.find_first_not_of(setofnums) != string::npos) 
        cout << "There's a non-number in here! 
";
    else
        cout << "All good!
";

    return 0; 
}
原文地址:https://www.cnblogs.com/minmsy/p/6028672.html