确保cout具有ctype< char>方面? [英] Is cout Guaranteed to Have the ctype<char> facet?

查看:82
本文介绍了确保cout具有ctype< char>方面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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()));

在线示例

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

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

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())

推荐答案

来自 cppreference :

在C ++程序中构造的每个语言环境至少都具有以下标准方面:[...]

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

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

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

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

这篇关于确保cout具有ctype&lt; char&gt;方面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆