C++ 国际化编程:从字符集到 Unicode
1. 字符计数与排序
1.1 字符计数程序
以下是一个用于统计输入单词出现次数的程序:
void print_pair(count_pair const& pair, str_size longest)
{
int constexpr count_size{10}; // Number of places for printing the count
std::cout << std::format("{0:{1}} {2:{3}}\n", pair.first, longest, pair.second, count_size);
}
void print_counts(count_map const& counts)
{
auto longest{get_longest_key(counts)};
// For each word/count pair...
for (count_pair pair: counts)
print_pair(pair, longest);
}
int main()
{
// Set the global locale to the native locale.
std::locale::global(std::locale{""});
initialize_streams();
count_map counts{};
sanitizer sanitize{std::locale{""}};
// Read words from the standard i
超级会员免费看
订阅专栏 解锁全文
2万+

被折叠的 条评论
为什么被折叠?



