且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C ++字符串中大写单词?

更新时间:2023-02-18 21:03:52

如果字符串确实只是一个单词,则 std :: string大写= boost :: locale :: to_title(示例)应该这样做。否则,您所拥有的将非常紧凑。

If the string is indeed just a single word, std::string capitalized = boost::locale::to_title (example) should do it. Otherwise, what you've got is pretty compact.

编辑:只是注意到 boost :: python 命名空间有一个 str 类和一个 capitalize()方法,听起来像它适用于多字串(假设您想要您描述的内容而不是标题的大小写)。但是,仅使用python字符串获得该功能可能不是一个好主意。

just noticed that the boost::python namespace has a str class with a capitalize() method which sounds like it would work for multi word strings (assuming you want what you described and not title case). Using a python string just to gain that functionality is probably a bad idea, however.