C++ Primer(第5版) 练习 17.16
练习 17.16 如果前一题程序中的regex对象用"[^c]ei"进行初始化,将会发生什么?用此模式测试你的程序,检查你的答案是否正确。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块:
/*************************************************************************
> File Name: ex17.16.cpp
> Author:
> Mail:
> Created Time: Sun 18 Aug 2024 09:09:23 AM CST
************************************************************************/
#include<iostream>
#include<regex>
using namespace std;
int main(){
string pattern("[^c]ei");
//pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
regex r(pattern);
smatch results;
string word;
while(cin>>word){
if(regex_search(word, results, r)){
cout<<"True"<<endl;
cout<<word<<endl;
}
else{
cout<<"False"<<endl;
}
}
return 0;
}