title: using getline gives error: no matching function for call to ‘getline(std::istream&, const string&)’
body: <p>I'm working on this code and it works with <code>cin&gt;&gt;partname;</code> instead of using <code>getline(cin, partname);</code> in the showpart function but for only names without blank space. But with using <code>getline(cin, partname);</code> it produces an error
  <code>error: no matching function for call to ‘getline(std::istream&amp;, const string&amp;)’</code></p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstring&gt;
  
  using namespace std;
  
  class Inventory
  {
    private:
      int partno;
      string partname;
      float cost;
      void getpart()
      {
        cout&lt;&lt;&quot;Enter the part number&quot;&lt;&lt;endl;
        cin&gt;&gt;partno;
        cout&lt;&lt;&quot;Enter the part name&quot;&lt;&lt;endl;
        cin&gt;&gt;partname;
        cout&lt;&lt;&quot;Enter the cost&quot;&lt;&lt;endl;
        cin&gt;&gt;cost;
      }
  
    public:
      Inventory()
      {
        partno = 0;
        partname = &quot; &quot;;
        cost = 0.0;
      }
  
      Inventory(int pn,string pname,float c)
      {
        partno = pn;
        partname = pname;
        cost = c;
      }
  
      void setpart()
      {
        getpart();
      }
  
      void showpart() const
      {
        cout&lt;&lt;&quot;Inventory details&quot;&lt;&lt;endl;
        cout&lt;&lt;&quot;Part Number: &quot;&lt;&lt;partno&lt;&lt;endl;
        cout&lt;&lt;&quot;Part Name: &quot;;
        getline(cin, partname);
        cout&lt;&lt;&quot;\nCost: &quot;&lt;&lt;cost&lt;&lt;endl;
      }
  };
  
  int main()
  {
    Inventory I1(1,&quot;Resistor&quot;, 25.0), I2;
    I2.setpart();
    I1.showpart();
    I2.showpart();
  }
  </code></pre>
  <p>I've looked through similar errors but they seem not to be helpful.Thank you for looking through this.</p>