By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,236 Members | 1,941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,236 IT Pros & Developers. It's quick & easy.

Using tolower in transform

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.