假设您有:
const char * something = "m";
如何使用 toupper(或其他工具,如果适用)将其变为大写?
我想使用 char *
而不是 string
(我可以使用字符串,但我必须使用 str.c_str()
)。
那么,如何让 char * something = "m";
包含 "M"
?
最佳答案
我发现你选择的 C 字符串令人不安......但无论如何。
您不能更改字符串文字 (char *something
)。尝试数组:
char something[] = "m";
something[0] = toupper(something[0]);
要更改整个字符串:
char something[] = "hello";
char *p = something;
while (*p) {
*p = toupper(*p);
p++;
}
关于c++ - 在 C++ 中转换为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8693990/