例如,用户可能输入一个ID号并创建一个函数,通过该ID号提取和打印第一个在3到8之间的数字?
例如。
。
发布于 2020-02-05 20:14:08
在注释上展开时,整数不一定是int
。例如
char five = '5';
存储在char
中的整数。也是
std::string x = "157567658";
是几个以std::string
表示的单数整数。
你需要的原料是:
将用户输入读入std::string
中的
std::string id;
std::cin >> id;
std::string
:中的所有字符
for (const char& c : id) {
// c are the elements of id
}
if ('3' <= c && c < '8') { // half-open ranges are most common
// do something with c
}
你只需要把事情搞清楚。
https://stackoverflow.com/questions/60083166
复制相似问题