qfedu-basic-level/day4/d12.cpp

24 lines
605 B
C++
Raw Permalink Normal View History

2023-06-16 09:15:39 +08:00
#include <iostream>
#include <regex> // 引入正则表达式库
using namespace std;
int main()
{
string x;
cout << "输入一个字符:" << endl;
cin >> x;
regex regex_lower("[a-z]");
regex regex_upper("[A-Z]");
cout << regex_match(x, regex_lower) << regex_match(x, regex_upper) << endl;
// 正则表达式
if (regex_match(x, regex_lower)) // regex_match 匹配正则表达式
{
cout << (char)(x.at(0) - 32) << endl; // .at(0) 获取第一个字符
}
else if (regex_match(x, regex_upper))
{
cout << (char)(x.at(0) + 32) << endl;
}
}