4

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())
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    FYI I closed that question as a dupe. You may want to move your answer to the target instead of having it on the linked to question. – NathanOliver May 25 '16 at 12:18
  • @NathanOliver Man the Roomba got to that fast. I gotta hurry up and get to 10k so I can see my answers on deleted questions! Anyway, I've typed something up from memory on the correct question: http://stackoverflow.com/a/37438120/2642059 Thanks for the heads up. – Jonathan Mee May 25 '16 at 13:07
  • 1
    [Here](http://pastebin.com/kkvYp7fj)(pastebin-link) is the source of your answer – NathanOliver May 25 '16 at 13:09
  • @NathanOliver Thanks, I appreciate you grabbing that for me! I've used it to update the answer, eliminating the link to: http://stackoverflow.com/a/37435426/2642059 – Jonathan Mee May 25 '16 at 13:17
  • hm guys the question linked gives a 404, "removed from stackoverflow by reasons of moderation" – coyotte508 May 25 '16 at 13:22
  • @coyotte508 Sounds like we both need to get to 10K so we can see that answer! I've updated the question with the relevant sections from my answer there. – Jonathan Mee May 25 '16 at 13:28
  • @NathanOliver HAHA! Finally made it to 10K! I can see the question again! Who knows what mayhem I can wreck with this new-found power! – Jonathan Mee May 26 '16 at 10:33
  • 1
    @JonathanMee Congrats, Now you can be power drunk like the rest of us ;-) – NathanOliver May 26 '16 at 11:34

1 Answers1

3

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>.

Community
  • 1
  • 1
coyotte508
  • 9,175
  • 6
  • 44
  • 63