c++ string

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

int main() { 

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

    while (cin.get(next) && (next != '\n')) {
        if (! isdigit(next)) 
            message = "There's a non-number in here! \n";
    }
    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! \n";
    else
        cout << "All good!\n";

    return 0; 
}

 

posted @ 2016-11-03 23:05  指间ゝ繁华初逝的格调  阅读(130)  评论(0编辑  收藏  举报