-
Transform help
I am doing lab for homework, I have the code seemingly correct except when I compile I get an error:
hangman.cpp 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>)'
Headers etc..
Code:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using std::transform;
int main ()
{
// declare variables
string origWord = "";
string letter = "";
char dashReplaced = 'F';
char gameOver = 'F';
int numIncorrect = 0;
string guessWord = "-----";
transform itself. I can post more parts if this does not show enough.
Code:
transform(origWord.begin(), origWord.end(), origWord.begin(), toupper);
Not sure why it is doing this, this is the only error (there are 2 transforms and both get same error)
-
Does it work with the global ::toupper?
-
using std::toupper? No same error.
-
Code:
transform(origWord.begin(), origWord.end(), origWord.begin(), tolower);
I tried this way too, to double check. Same error.
-
It doesn't like toupper, because it's ambiguous. Try:
Code:
transform(origWord.begin(), origWord.end(), origWord.begin(), (int(*)(int)) toupper) );
Source: http://www.devx.com/getHelpOn/Article/9702/1954
-
Crap that works perfect. Wonder why the book was wrong? Or could it be that I left something else out?
Thanks for your help.
-
Maybe:
... might help to include the header that actually contains the prototype for that function.
-
Nope, I changed it back and added the cctype header and got the same error. I thought it (toupper) was covered under <iostream>? Tranform is supposed to be <algorithm>