473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using tolower in transform

Hello,

i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?

--
TheDD
Jul 22 '05 #1
11 3320
TheDD wrote:
Hello,

i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);
Wouldn't

transform(str.begin(), str.end(), str.begin(), tolower);

do the trick?

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?


Not sure.

Victor
Jul 22 '05 #2
Victor Bazarov wrote:
[...]
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);


Wouldn't

transform(str.begin(), str.end(), str.begin(), tolower);

do the trick?


yes it does, thx a lot.

But in this case, i guess the used locale is "C". What can i do to use
another one?

--
TheDD
Jul 22 '05 #3
TheDD wrote:
Victor Bazarov wrote:

[...]
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);


Wouldn't

transform(str.begin(), str.end(), str.begin(), tolower);

do the trick?

yes it does, thx a lot.

But in this case, i guess the used locale is "C". What can i do to use
another one?


Good question. Could you temporarily set it as "global one to use"
somehow? I am not that familiar with locales, as you probably figured
out by now...

V
Jul 22 '05 #4
Victor Bazarov wrote:
Good question. Could you temporarily set it as "global one to use"
somehow? I am not that familiar with locales, as you probably figured
out by now...


Well i can use:

locale::global(locale(""));

but it's not really great. I'm going to read the docs one more time :)

--
TheDD
Jul 22 '05 #5
TheDD wrote:
i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);
If you have to use a member function, try something like

std::transform(str.begin(), str.end(), str.begin(),
std::bind1st(std::mem_fun(&ctype<char>::tolower), ct));

I couldn't get it to compile, but dig in that direction.

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?


To use a member function, you need 'mem_fun'.

Victor
Jul 22 '05 #6
On Fri, 28 May 2004 22:18:50 +0200, TheDD <pa*********@pas.de.spam.fr>
wrote:
Hello,

i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>
#include <cstdlib>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?


You need to include a library that includes tolower.

rossum
(Who has done the same sort of thing more often than he cares to
remember.)
--

The Ultimate Truth is that there is no Ultimate Truth
Jul 22 '05 #7
Le 28/05/2004 à 23:29:31, rossum <ro******@coldmail.com> a écrit:
On Fri, 28 May 2004 22:18:50 +0200, TheDD <pa*********@pas.de.spam.fr>
wrote:
Hello,

i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>


#include <cstdlib>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?


You need to include a library that includes tolower.

rossum
(Who has done the same sort of thing more often than he cares to
remember.)


same error message, doesn't seem to be that.

--
TheDD
Jul 22 '05 #8
Victor Bazarov wrote:
If you have to use a member function, try something like

std::transform(str.begin(), str.end(), str.begin(),
std::bind1st(std::mem_fun(&ctype<char>::tolower), ct));

I couldn't get it to compile, but dig in that direction.


Well i don't have a member function.

This works:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>
#include <functional>

using std::cout;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::bind2nd;

struct s : std::binary_function< char, locale, char >
{
char operator ()(char c, const locale & loc) const
{
/* use:
* template<typename CharT>
* CharT std::tolower ( CharT c,
* const locale & __loc
* )
*/
return std::tolower(c, loc);
}
};

int
main()
{
locale loc("");
string str("Hello world.");

// use s operator ()
transform(str.begin(), str.end(),
str.begin(), bind2nd(s(), loc));

cout << str << endl;
return 0;
}
but is really not classy.

--
TheDD
Jul 22 '05 #9
"TheDD" <pa*********@pas.de.spam.fr> wrote...
Victor Bazarov wrote:
If you have to use a member function, try something like

std::transform(str.begin(), str.end(), str.begin(),
std::bind1st(std::mem_fun(&ctype<char>::tolower), ct));

I couldn't get it to compile, but dig in that direction.


Well i don't have a member function.


If you didn't, why were you trying to say

ct.tolower

? Isn't the notation '.' meant for member access? I must
be missing something here...

V
Jul 22 '05 #10
"TheDD" <pa*********@pas.de.spam.fr> wrote in message
news:c9**********@news-reader5.wanadoo.fr...
Hello,

i don't manage to use the tolower() function:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>

using std::cout;
using std::ctype;
using std::endl;
using std::locale;
using std::string;
using std::transform;
using std::use_facet;

typedef ctype< char > char_ctype_facet;

int
main()
{
locale loc("");
const char_ctype_facet& ct = use_facet< char_ctype_facet >(loc);
string str("Hello world.");

transform(str.begin(), str.end(),
str.begin(), ct.tolower);

cout << str << endl;
return 0;
}

$ g++ -W -Wall -std=c++98 -pedantic tolower.cc
tolower.cc: In function `int main()':
tolower.cc:24: error: no matching function for call to
`transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'

ct.tolower is <unknow type>

What am i doing wrong?
I am not sure, but it might be related to:
Bug#144409: g++-3.0: does not support transform(begin,end,begin,tolower)
idiom
http://lists.debian.org/debian-gcc/2.../msg00092.html

--
TheDD

Jul 22 '05 #11
Le 29/05/2004 à 02:11:45, Victor Bazarov <v.********@comAcast.net> a
écrit:
If you have to use a member function, try something like

std::transform(str.begin(), str.end(), str.begin(),
std::bind1st(std::mem_fun(&ctype<char>::tolower), ct));

I couldn't get it to compile, but dig in that direction.


Well i don't have a member function.


If you didn't, why were you trying to say

ct.tolower

? Isn't the notation '.' meant for member access? I must
be missing something here...


My mistake, sorry :p

--
TheDD
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: qazmlp | last post by:
I was using the following code to convert the string to lowercase. string foo = "Some Mixed Case Text"; transform(foo.begin(), foo.end(), foo.begin(), tolower); I thought the above code is...
13
by: David Rubin | last post by:
I get an error when I compile the following code: #include <algorithm> #include <cctype> #include <iostream> #include <string> using namespace std; string&
3
by: Ahsan | last post by:
Hi All, I am having prolems with converting upper case characters to lower case in Unix's C. I saw the man pages and "tolower" function does it. But in my case its not working. My code is as...
2
by: Daniel Aarno | last post by:
As far as I can tell the locale header should provide a tolower function however the following failes for me under gcc 3.4. transform(begin, end, begin2, std::tolower); with an error that the...
4
by: Eric Lilja | last post by:
Hello, consider this program: #include <iostream> #include <algorithm> #include <string> #include <cctype> int main() { std::string s = "HEJ";
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
10
by: Anthony Williams | last post by:
Hi gang, This one looks like a bug :o( As you may or may not know, setting session management in web.config to use cookieless sessions causes the ASP.NET runtime to munge a session ID into...
5
by: Faray | last post by:
Hello, this is my first post, so hopefully I am posting this in the right place. Hopefully someone will be able to help me out with my problem here it is: I need to make a program that ask a...
13
by: Soumen | last post by:
I wanted convert a mixed case string to a lower case one. And I tried following code: std::transform(mixedCaseString.begin(), mixedCaseString::end(), mixedCaseString.begin(),...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.