#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
string s;
cin.ignore();//非常关键 忽略输入流的一个字符(默认参数为1)
while (n--&&getline(cin, s))
{
int flag = 1;
if (!(s[0] == '_' || (s[0] <= 'Z'&&s[0] >= 'A') || (s[0] <= 'z'&&s[0] >= 'a')))
{
cout << "no" << endl;
continue;
}
for (auto c : s)
{
if (!(c == '_' || (c <= 'Z'&&c >= 'A') || (c <= 'z'&&c >= 'a') || (c >= '0'&&c <= '9')))
{
cout << "no" << endl;
flag = 0;
break;
}
}
if (flag)
cout << "yes" << endl;
}
}
return 0;
}
ignore函数:
功能:函数用于输入流。它读入字符,直到已经读了num 个字符(默认为1)或是直到字符delim 被读入(默认为EOF).
其调用形式为cin.ignore(n,终止字符)
原型:istream &ignore( streamsize num=1, int delim=EOF );
函数作用是跳过输入流中n个字符,或在遇到指定的终止字符时提前结束(此时跳过包括终止字符在内的若干字符)。
功能:函数用于输入流。它读入字符,直到已经读了num 个字符(默认为1)或是直到字符delim 被读入(默认为EOF).
其调用形式为cin.ignore(n,终止字符)
原型:istream &ignore( streamsize num=1, int delim=EOF );
函数作用是跳过输入流中n个字符,或在遇到指定的终止字符时提前结束(此时跳过包括终止字符在内的若干字符)。
程序举例:
#include <iostream>
using namespace std;
int main()
{
char array[8];
cin.ignore(6,'a');
cin.getline(array,8);
cout<<array<<endl;
return 0;
}
它还可以这样用:
cin.ignore();
即不带参数;此时默认参数为1.