判断是否为C++合法标识符

来源:互联网 发布:英文写作润色软件 编辑:程序博客网 时间:2024/06/10 16:19

判断是否为C++合法标识符

需要C++11的支持

源代码

#include <iostream>#include <regex>#include <string>using namespace std;bool Jugement(const string &temp_str) {    regex reg("[_[:alpha:]][_[:alnum:]]*");    if (regex_match(temp_str, reg)) {        return true;    }    else {        return false;    }}void F() {    string temp_str;    cout << "请输入字符串: " << endl;    while (cin >> temp_str) {        cout << temp_str << "    ";        if (Jugement(temp_str)) {            cout << "yes" << endl;        }        else {            cout << "no" << endl;        }    }}int main() {    F();    return 0;}
0 0
原创粉丝点击