c++ setting string attribute value in class is throwing "Access violation reading location"
<p>I am having some trouble getting this simple code to work:</p>

<pre><code>#pragma once
#include &lt;iostream&gt;
#include &lt;string&gt;
using std::string;

class UserController;
#include "UserController.h"
class CreateUserView
{
public:
 CreateUserView(void);
 ~CreateUserView(void);
 UserController* controller;
 void showView();

 string name;
 string lastname;
 string address;
 string email;
 string dateOfBirth;
};
</code></pre>

<p>All i need is to set these attributes in the implementation with getline().</p>

<pre><code>CreateUserView::CreateUserView(void)
{

}
void CreateUserView::showView()
{

 cout &lt;&lt; endl &lt;&lt; "  New User" &lt;&lt; endl;
 cout &lt;&lt; "--------------------------" &lt;&lt; endl;
 cout &lt;&lt; "  Name\t\t: ";
 getline(cin, name);

 cout &lt;&lt;  "  Lastname\t: ";
 getline(cin, lastname);

 cout &lt;&lt; "  Email\t\t: ";
 getline(cin, email);


 cout &lt;&lt; "  ===============================" &lt;&lt; endl;
 cout &lt;&lt; "   1. SAVE   2.CHANGE   3.CANCEL" &lt;&lt; endl;
 cout &lt;&lt; "  ===============================" &lt;&lt; endl;
 cout &lt;&lt; "  choice: ";
 int choice;
 cin &gt;&gt; choice;
 cin.ignore();

 controller-&gt;createUser_choice(choice);
}
</code></pre>

<p>I keep getting this "Access violation reading location" error at this line:</p>

<pre><code>getline(cin, name);
</code></pre>

<p>what's the best way of assigning a value to an std::string attribute of a class?
even name = "whatever" is throwing that error!!</p>

<p>thanks</p>

<p><strong>EDIT:</strong>
a UserController is instantiating the CreateUserView:</p>

<pre><code>CreateUserView *_createUserView;
</code></pre>

<p>This how the CreateUserView is being instantiated:</p>

<pre><code>void UserController::createUser()
{
    //Init the Create User View
    if(_createUserView == NULL)
    {
        _createUserView = new CreateUserView();
        _createUserView-&gt;controller = this;
    }
    _createUserView-&gt;showView();
}
</code></pre>
