help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tolower - std namespace?


From: Taras_96
Subject: Re: tolower - std namespace?
Date: Wed, 19 Mar 2008 06:07:32 -0700 (PDT)
User-agent: G2/1.0

On Mar 15, 5:12 pm, Thomas Maeder <mae...@glue.ch> wrote:
>
> Unfortunately, the situation is more complicated:
> - <cctype> declares the 1 argument version of std::tolower()
> - <locale> declares the 2 argument version of std::tolower()
> - in C++, <ctype.h> works like <cctype> but adds a using declaration
>   for std::tolower in the global namespace
>
> And in reality, C++ implemetations often don't implement the 3rd item
> correctly. So the best thing IMHO is to not #include <ctype.h> in new
> code and rely on the tolower() overloads in namespace std.
>
> > This link (http://www.thescripts.com/forum/thread161158.html) states
> > that std::tolower takes two arguments, not one. This link
> > (http://www.cplusplus.com/reference/clibrary/cctype/tolower.html)
> > shows that the tolower in cctype.h takes a single argument. I am
> > also aware that transform must take a binary argument.
>
> There is no such thing as <cctype.h> in C++. It's either <cctype> or
> <ctype.h>. Both declare a 1 argument version of std::tolower().
>

You've actually brought up a couple of other points I have questions
about. Firstly about the difference between <ctype.h> and <cctype>

The post at http://www.thescripts.com/forum/thread60652.html states
that:

"The problem is that most implementations of the standard C <ctype.h>
header define functions like toupper/tolower/etc as macros. To make it
work in STL algorithms, you have to include <cctype> header instead of
<ctype.h>. At least on my PC (Debian/gcc 3.3), <cctype> undefines all
tolower/etc macros and pulls ::tolower/::toupper/etc functions into
std namespace, so that your sample will work fine."

Is this accurate (in that it won't work because the functions are
macros)?

By the way, the function call was:

string foo = "Some Mixed Case Text";
transform(foo.begin(), foo.end(), foo.begin(), tolower);

Taras


reply via email to

[Prev in Thread] Current Thread [Next in Thread]