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

﹥>﹥吖頭↗ 提交于 2019-12-10 16:20:06

问题


Given: auto foo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"s I can convert all the characters to lowercase by:

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

Live Example

But this depends upon cout.getloc() containing the ctype<char> facet.

Presuming that I'm using an unmodified cout can I assume that cout.getloc() will contain the facet ctype<char> or do I need to confirm this before use with:

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

回答1:


From cppreference:

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

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

Any locale, meaning even locales not of the cout object will support std::ctype<char>.



来源:https://stackoverflow.com/questions/37436755/is-cout-guaranteed-to-have-the-ctypechar-facet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!