Friday, April 29, 2011

string inserting error c++

WordChosenDuplicate.insert(0,WordChosen.length," _ ");
    cout <<WordChosenDuplicate<< endl;

I get the following error when I try to run this code

error C3867: 'std::basic_string<_Elem,_Traits,_Ax>::length': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Ax>::length' to create a pointer to member c:\documents and settings\main\my documents\uni\2nd year\tp2\hangman\hangman\hangman.cpp 119
From stackoverflow
  • It's a function: std::string::length()

    Please read the Manuals available on the net and the answers posted to your previous questions.

  • You need to use WordChosen.length (). Add the parenthesis, this is a method call.

  • for (int f = 0; f <= WordChosen.length()-1;f++)
        {
    
          WordChosenDuplicate.insert(0,(WordChosen.length(),"_ "));
    
        }
    
        cout <<WordChosenDuplicate<< endl;
    

    Thanks guys got the answer.

    dirkgently : Do you know why, if at all, this works? (I take that works == compiles for the moment.)
    : yip it compiles.Is for a hangman game so that was just making the blanks spaces for the word.
    dirkgently : :sigh: I wish people take the ',' as an operator and not neglect its ramifications.

0 comments:

Post a Comment