Help With C++ Pointer Arrays Please

Discussion in 'Gaming' started by White B O I, Jun 16, 2009.

  1. White B O I

    White B O I Well-Known Member

    Age:
    36
    Posts:
    813
    Likes Received:
    0
    Joined:
    Apr 11, 2006
    Location:
    Table Town, Arizona
    I understand arrays :
    Code:
    int x[3];
    
    x[0] = 4;
    i also understand pointers.
    Code:
        int i = 5;
        int* pi;
        
        pi = &i;
        
        cout << pi << " " << *pi << endl;
    // this will set the pointer pi == to i, which is 5. When you run it
    //it will display first the address, then it will point to the contents
    // of pi, which is 5. So it will display some address 5
    I also understand pointer arithmetic,
    Code:
    int i[5];
        int* pi;
        
        i[2] = 4;
        pi = &i[0];
        
        cout << pi << " " << *(pi+2) << endl;
    //this will display the address of i and then the contents of pi+2 which is i[2]
    I have a finaly in a few days and I'm having difficulties

    I cant seem to use cin with pointer arithemitic.
    such as

    Code:
     
    int i=0;
    cin.sync();
    getline(cin,*(ptrX + i);
    here is my code, I just began witting it, I'm not nearly done. It's a pre-Final.
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    class Monsters
    {
    private: 
             string mName;
             string *monster;
             string eyeColor;
    public:
           Monsters()
          { 
          }
          
          ~Monsters()
          {
          }
          
          void mBorn(int i = 0, string newMonster)
          {   
              *monster = newMonster;
              
              cout << "Name of your new monster: ";
              getline(cin,*(monster+i));
               
               i++;
               
          }
          
          void mEyeColor(string newEyeColor)
          {
          eyeColor = newEyeColor;
          
          cout << "What is the color of your monsters eyes?";
          cin >> eyeColor;
          }
    };      
    
    int main(int argc, char *argv[])
    {
        
    Monsters Test;
    //the following is for testing purposes only, it calls the mBorn function, which doesn't run properly.
        int i;
        string x;
        Test.mBorn(i,x);
    
        system("PAUSE");
        return EXIT_SUCCESS;
    
    }
    I'm using Dev Bloodshed 4.9.9.2 (newest), my teacher requires it.

    My program compiles, but doesn't run.
     

Share This Page