cout 是否保证有 ctype<char> 方面?

Is cout Guaranteed to Have the ctype<char> facet?

鉴于:auto foo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"s我可以通过以下方式将所有字符转换为小写:

use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size()));

Live Example

但这取决于 cout.getloc() 包含 ctype<char> facet.

假设我使用的是未修改的 cout 我可以假设 cout.getloc() 将包含 facet ctype<char> 还是我需要在使用前确认这一点:

has_facet<ctype<char>>(cout.getloc())

来自cppreference

Each locale constructed in a C++ program holds at least the following standard facets [...]:

  1. std::ctype<char>
  2. ...

任何 语言环境,这意味着即使不是 cout 对象的语言环境也将支持 std::ctype<char>.