C++ error: cast from ‘char*’ to ‘int’ loses precision
<p>I started learning C++ a few days ago.</p>

<p>I want to set <code>dog.age</code> using user input.</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

class dog{
    public:
        dog();
        ~dog();
        int getAge();
        void setAge(int a);

    protected:
        int age;
};

dog::dog(){

}

dog::~dog(){

}

int dog::getAge(){
    return age;
}

void dog::setAge(int a){
    age = a;
}

int main(){
    dog myDog;
    char myString[2];
    int age;

    cout&lt;&lt;"How old is the dog? ";
    cin.getline(myString,2,'\n');

    age = (int)myString;
    myDog.setAge(age);
    cout&lt;&lt;"The dog is "&lt;&lt;myDog.getAge()&lt;&lt;" years old!\n";
    return 0;
}
</code></pre>

<p>But I get this error: </p>

<pre><code>error: cast from ‘char*’ to ‘int’ loses precision [-fpermissive]
  age = (int)myString;`
</code></pre>

<p>Even if I remove <code>(int)</code>, it fails.</p>

<p>Why won't my program cast <code>myString</code> as an <code>int</code>?</p>

<p>OPTIONAL: If I'm doing something else wrong with constructing classes, feel free to tell me. I'd like to kick bad habits early.</p>