使用c++语言,利用vector容器实现以下功能3、给定一个字符串,将其中所有的小写字母转换成大写字母。 例如:输入helloworld123Ha,输出HELLOWORLD123HA。
时间: 2024-05-09 08:19:53 浏览: 7
```c
#include <stdio.h>
#include <ctype.h>
#include <vector>
int main() {
std::vector<char> strVec;
char c;
while ((c = getchar()) != '\n') {
strVec.push_back(toupper(c));
}
for (auto c : strVec) {
printf("%c", c);
}
printf("\n");
return 0;
}
```
相关问题
给定一个字符串,将其中所有的小写字母转换成大写字母。C++
可以使用 C++ 中的 toupper 函数将小写字母转换成大写字母,具体实现如下:
```cpp
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s[] = "Hello, World!";
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') { // 如果是小写字母
s[i] = toupper(s[i]); // 转换成大写字母
}
}
cout << s << endl; // 输出转换后的字符串
return 0;
}
```
输出结果为:
```
HELLO, WORLD!
```
给定一个字符串,将其中所有的小写字母转换成大写字母,用C++来写
下面是一个使用 C 语言将字符串中所有小写字母转换为大写字母的示例代码:
```
#include <stdio.h>
#include <ctype.h>
void toUpper(char *str) {
int i;
for (i = 0; str[i]; i++) {
str[i] = toupper(str[i]);
}
}
int main() {
char str[] = "hello, world!";
printf("Original string: %s\n", str);
toUpper(str);
printf("Uppercase string: %s\n", str);
return 0;
}
```
该代码使用了 `toupper` 函数,它是 C 标准库中的一个函数,用于将小写字母转换为大写字母。