Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cygwin compilation error for std::transform function

7 views
Skip to first unread message

Gaurav

unread,
Dec 13, 2002, 12:27:19 AM12/13/02
to
Hi There,

I have a small program that works fine on my older version of cygwin
but not on latest version.

code is :
*********************************
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main (){
string s;
s = " Hi There";
cout<<s<<endl;

//need #include<algorithm>
transform( s.begin(), s.end(), s.begin(), tolower );

//prints in lower case
cout<<s<<endl;
return 0;
}

***********************************

Error message on compilation in latest version of cygwin
****************************
$ g++ testtransform.cpp
testtransform.cpp: In function `int main()':
testtransform.cpp:14: 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>)'
****************************

Can someone tell me whats going on here ?

Thank you in advance.

Regards,
Gaurav

Victor Bazarov

unread,
Dec 13, 2002, 12:36:47 AM12/13/02
to
"Gaurav" <bansa...@yahoo.com> wrote...

> I have a small program that works fine on my older version of cygwin
> but not on latest version.
> [...]

Could it be you needed to include some header for 'tolower'?

Victor
--
Please remove capital A's from my address when replying by mail


Victor Bazarov

unread,
Dec 13, 2002, 9:40:26 AM12/13/02
to
"Owen Jacobson" <ojac...@mx-deus.trappenspammen.net> wrote...
> Allegedly, "Victor Bazarov" <v.Aba...@attAbi.com> wrote:
>
> Jung, lbh zrna ur sbetbg #vapyhqr <ppglcr>?
> --
> When all else fails, run.
>

Excuse me...


Cagdas Ozgenc

unread,
Dec 13, 2002, 10:20:32 AM12/13/02
to
This happens on GCC as well. I submitted it as a bug, but the implementers
told me it was not (I think they just ignored me).

What I did was to cast "tolower" to its type (basically useless but it
forces the compiler).

transform(s.begin(),s.end(),s.begin(),((int)(*)(int)tolower));

"Gaurav" <bansa...@yahoo.com> wrote in message
news:557c3f87.02121...@posting.google.com...


> Hi There,
>
> I have a small program that works fine on my older version of cygwin
> but not on latest version.
>
> code is :
> *********************************
> #include <iostream>
> #include <string>
> #include <algorithm>
> using namespace std;
>
> int main (){
> string s;
> s = " Hi There";
> cout<<s<<endl;
>

> file://need #include<algorithm>


> transform( s.begin(), s.end(), s.begin(), tolower );
>

> file://prints in lower case

Tom

unread,
Dec 13, 2002, 10:55:43 AM12/13/02
to
bansa...@yahoo.com (Gaurav) wrote in message news:<557c3f87.02121...@posting.google.com>...

Two things. First, you should add "#include <cctype>" for
std::tolower. Second, for slightly obscure reasons, tolower returns an
int rather than a char. Therefore, std::transform, which is looking
for a function returning a char in your example, doesn't see tolower
because it returns an int. One solution is to add your own function:

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

#include <cctype>
using namespace std;

char myTolower(char c)
{
return char(tolower(c));
}

int main ()
{
string s;
s = " Hi There";
cout<<s<<endl;

transform( s.begin(), s.end(), s.begin(), myTolower );

//prints in lower case
cout <<s << endl;
return 0;
}

The older version of Cygwin probably used GCC 2.95, which was less
standard-conforming than the GCC 3.2, the current version.

Hope that helps.

Best regards,

Tom

Alexander Terekhov

unread,
Dec 13, 2002, 11:27:45 AM12/13/02
to

For what, Bazarov?

#include <string>
#include <cctype>
#include <climits>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;

class rot13: public unary_function< char, char > {

char table[ UCHAR_MAX+1 ];

public:

rot13() {
static const unsigned char a[] = "abcdefghijklmnopqrstuvwxyz";
for ( int i = 0; i <= UCHAR_MAX; i++ )
table[ i ] = i;
for ( int c = 0; c < 26; c++ ) {
int r = (c + 13) % 26;
table[ a[ c ] ] = a[ r ];
table[ toupper( a[ c ] ) ] = toupper( a[ r ] );
}
}

char operator()( char c ) const {
return table[ c ];
}

};

int main() {
string message = "Jung, lbh zrna ur sbetbg #vapyhqr <ppglcr>?";
transform( message.begin(), message.end(),
ostream_iterator<char>( cout, "_" ), rot13() );
cout << " ;-) \n";
}

regards,
alexander.

Alf P. Steinbach

unread,
Dec 13, 2002, 4:29:27 PM12/13/02
to

Heh heh... :-)

I'm beginning to like certain aspects of your style.


Cheers,

- Alf

0 new messages