Can anyone tell me why this doesn't work? I know it's probably really easy, but I did try....

/* ISU program created by Matt 
   in grade 12 programming. */
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
class humanPlayer
          humanPlayer(char thePlayersName, unsigned int thePlayersTurnNum); //constructor
          void addToList(unsigned int countryToAdd) {countriesOwned.push_back(countryToAdd);} 
          void showList();
          void removeFromList(unsigned int countryToRemove) {countriesOwned.remove(countryToRemove);}
          void checkIfInList(unsigned int countryToCheck);
          char returnPlayerName() {return playerName;}  
          list<int> countriesOwned;
          char playerName;
          unsigned int playerTurnNum;
     humanPlayer::humanPlayer(char thePlayersName, unsigned int thePlayersTurnNum)
          playerName = thePlayersName;
          playerTurnNum = thePlayersTurnNum;
     void humanPlayer::checkIfInList(unsigned int countryToCheck)
          if(find(countriesOwned.begin(), countriesOwned.end(), countryToCheck) != countriesOwned.end())
               cout << countryToCheck << " is in the list.\n";
               cout << countryToCheck << " is NOT in the list.\n";
     void humanPlayer::showList()
          copy(countriesOwned.begin(),countriesOwned.end(),ostream_iterator<int>(cout,", "));
          cout << endl;
int main()
     humanPlayer test("Matt", 1);
9 Years
Discussion Span
Last Post by Narue

This is a string.

>char thePlayersName
This is not a string.

Since you don't seem to understand the difference between a char and a pointer to char, you should stick to using std::string objects.


>How would I go about using std::string things for what I need?
You start by getting a relatively modern book on C++. I'd recommend Accelerated C++ by Andrew Koenig and Barbara Moo. It uses strings religiously. What you're trying to do now is use C-style strings, but I get the feeling that your command of pointers is weak, so any attempt at using C-style strings properly is assured to fail. std::strings are much easier to use. But don't forget to include <string>.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.