#include <iostream> #include <___________> using namespace std; int main() {char s[80],*p; int U,L,D; ______________________; gets(s); for(_________;*p!='\0'; ___________) if(isupper(*p)) U++; else if(islower(*p)) L++; else if(___________) D++; cout<<"字符串"<<_______<<"中含有:"<<endl; cout<<U<<"个大写字母"<<endl; cout<<L<<"个小写字母"<<endl; cout<<D<<"个数字字符"<<endl; return 0; }
时间: 2023-08-20 20:09:22 浏览: 33
#include <cctype> //需要包含头文件cctype
using namespace std;
int main() {
char s[80], *p;
int U = 0, L = 0, D = 0; //初始化计数器为0
cout << "请输入字符串:";
gets(s);
p = s;
while (*p != '\0') { //遍历字符串
if (isupper(*p)) //判断是否为大写字母
U++;
else if (islower(*p)) //判断是否为小写字母
L++;
else if (isdigit(*p)) //判断是否为数字字符
D++;
p++; //指针移动到下一个字符
}
cout << "字符串" << s << "中含有:" << endl;
cout << U << "个大写字母" << endl;
cout << L << "个小写字母" << endl;
cout << D << "个数字字符" << endl;
return 0;
}
相关问题
统一文件名只用#include<iostream> #include<string.h>
这两个头文件的作用不同,<iostream> 是用于输入输出流的库,而<string.h> 是用于字符串处理的库。如果你的程序中需要使用字符串相关函数,如strcpy、strlen等,就需要用到<string.h>头文件。如果要使用cout和cin等输入输出流对象则需要使用<iostream>头文件。如果你两个都需要用到,那么你就需要同时包含这两个头文件。例如:
```cpp
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char str1[10] = "hello";
char str2[10] = "world";
strcat(str1, str2); // 使用<string.h>中的字符串拼接函数strcat
cout << str1 << endl; // 使用<iostream>中的输出流对象cout
return 0;
}
```
#include<iostream> using namespace std; int main(int argc, char *argv[]) { return 0; }
这是一个简单的 C++ 程序,它的作用是输出一个整数 0 并返回给操作系统。其中:
- #include<iostream> 是 C++ 的头文件,它包含了输入输出流的定义。
- using namespace std; 声明使用 std 命名空间,这样我们就可以直接使用 std 中的函数和对象。
- int main(int argc, char *argv[]) 是程序的主函数,它接受两个参数:argc 表示命令行参数的数量,argv 是一个指向字符指针的指针,它存储了这些参数的值。
- return 0; 是程序的返回值,它表示程序执行完毕并成功返回。