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
Could it be you needed to include some header for 'tolower'?
Victor
--
Please remove capital A's from my address when replying by mail
Excuse 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
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
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.
Heh heh... :-)
I'm beginning to like certain aspects of your style.
Cheers,
- Alf