title: simple way to add string in a linked list
body: <p>I have a code to implement linked list it works fine. I want to include a string into the linked list however when I did add string, I got a run time error crashes the program when it reaches this line: </p>
  
  <pre><code>new_node-&gt;name = "hello";
  </code></pre>
  
  <p>The complete code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct list_item
  {
      int key;
      int value;
      string name;
      list_item *next;
  };
  
  struct list
  {
      struct list_item *first;
  };
  
  int main()
  {
      //Just one head is needed, you can also create this
      // on the stack just write:
      //list head;
      //head.first = NULL;
      list *head = (list*)malloc(sizeof(list));
      list_item *new_node = NULL;
      head-&gt;first = NULL;
  
      for(int i = 0; i &lt; 10; i++)
      {
          //allocate memory for new_node
          new_node = (list_item*)malloc(sizeof(list_item));
          //adding the values
          new_node-&gt;key = i;
          new_node-&gt;name = "hello";
          new_node-&gt;value = 10 + i;
  
          //if the list is empty, the element you are inserting
          //doesn't have a next element
  
          new_node-&gt;next = head-&gt;first;
  
          //point first to new_node. This will result in a LIFO
          //(Last in First out) behaviour. You can see that when you 
          //compile
          head-&gt;first = new_node;
  
      }
  
       //print the list 
       list_item *travel;
       travel = head-&gt;first;
  
       while(travel != NULL)
       {
           cout &lt;&lt; travel-&gt;value &lt;&lt; endl;
           cout &lt;&lt; travel-&gt;name &lt;&lt; endl;
           travel = travel-&gt;next;
       }
  
      //here it doesn't matter, but in general you should also make
      //sure to free the elements
      return 0;
  }
  </code></pre>
  
  <p>could anyone please help me how to include a string by the right way in c++?</p>