【发布时间】:2019-01-23 21:33:39
【问题描述】:
所以我已经找到了 How to capitalize a word in a C++ string? ,但我尝试了建议的类似代码,包括 Boost::locale 示例中提供的代码。我还将包括我的代码当前是什么以及预期和实际输出是什么。所以我试图理解为什么我没有得到预期的输出。
代码
#include <iostream>
#include <string>
#include <boost/locale.hpp>
#include <boost/algorithm/string/case_conv.hpp>
int main() {
using namespace std;
using namespace boost::locale;
generator gen;
auto loc = gen("");
locale::global(loc);
cout.imbue(loc);
ios_base::sync_with_stdio(false);
cout << to_upper("hello!") << " " << boost::to_upper_copy("hello!"s) << endl;
cout << to_lower("HELLO!") << " " << boost::to_lower_copy("HELLO!"s) << endl;
cout << to_title("hELLO!") << endl;
cout << fold_case("HELLO!") << endl;
return 0;
}
预期输出
HELLO! HELLO!
hello! hello!
Hello!
hello!
实际输出
HELLO! HELLO!
hello! hello!
hELLO!
hello!
其他信息
- 操作系统:Windows 10 家庭版 64 位
- 编译器:Microsoft Visual Studio 15.8.0
- 平台:x64
- 非默认编译选项:
/std:c++latest - BOOST_VERSION:106700
编辑#1
vcpkg 安装的 Boost 好像没有编译
与 ICU,这显然是 boost::locale::to_title 所必需的
功能正常。
【问题讨论】:
-
您是否在 ICU 支持下建立了提升?似乎
to_title仅支持 ICU -
在 Linux、GCC 7、Boost 1.67、ICU 上为我工作
-
@miradham 我使用的 boost 是由 vcpkg 自动构建的,所以我不知道,但这似乎很可能。
-
看起来我可以使用 vcpkg 安装基于 ICU 的 boost 库版本。现在我只需要等待至少几个小时,才能再次完全重新编译 boost。
标签: c++ string boost title-case boost-locale