【发布时间】:2011-05-11 09:51:51
【问题描述】:
嗨, 我需要一个可移植的函数来将 C++ 中的字符串转换为大写。我现在正在使用 toupper(char);功能。它是标准功能吗?如果不是,那么跨平台执行此操作的正确方法是什么?顺便说一句,有没有可以列出所有 C++ 标准函数的网络/维基?谢谢。
【问题讨论】:
标签: c++ cross-platform standard-library c++-standard-library
嗨, 我需要一个可移植的函数来将 C++ 中的字符串转换为大写。我现在正在使用 toupper(char);功能。它是标准功能吗?如果不是,那么跨平台执行此操作的正确方法是什么?顺便说一句,有没有可以列出所有 C++ 标准函数的网络/维基?谢谢。
【问题讨论】:
标签: c++ cross-platform standard-library c++-standard-library
对于后一个问题,有http://www.cplusplus.com/。
【讨论】:
您好,在我们的项目中,我们在 windows 和 linux 中使用 boost/algorithm/string to_upper 函数项目
【讨论】:
是的,toupper 在 cctype 标头中声明。您可以使用算法转换字符串:
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
int main()
{
std::string str("hello there");
std::cout << str << '\n';
std::transform(str.begin(), str.end(), str.begin(), std::toupper);
std::cout << str << '\n';
}
【讨论】: