Thread: Transform help

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    38

    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)

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Does it work with the global ::toupper?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    38
    using std::toupper? No same error.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    38
    Code:
     transform(origWord.begin(), origWord.end(), origWord.begin(), tolower);
    I tried this way too, to double check. Same error.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    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
    Last edited by syzygy; 04-27-2010 at 05:26 PM.

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    38
    Crap that works perfect. Wonder why the book was wrong? Or could it be that I left something else out?
    Thanks for your help.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Maybe:
    Code:
    #include <cctype>
    ... might help to include the header that actually contains the prototype for that function.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    38
    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>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d Cubik program in C
    By joot43 in forum C Programming
    Replies: 4
    Last Post: 05-25-2009, 07:17 AM
  2. Using Opengl to transform images
    By Cogman in forum Game Programming
    Replies: 2
    Last Post: 01-16-2009, 06:19 PM
  3. how to transform integer to char..
    By transgalactic2 in forum C Programming
    Replies: 7
    Last Post: 01-09-2009, 08:34 AM
  4. what is an elegant way to transform request to response?
    By kypronite in forum Networking/Device Communication
    Replies: 1
    Last Post: 12-24-2008, 10:47 AM
  5. transform help!!!
    By what3v3r in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2006, 10:27 PM