title: Error C2664: 'sprintf' : cannot convert parameter 1 from 'std::string' to 'char *'
body: <p>Below is the insert function in VC++.
  I am getting this error when I change the char to string data type to read the value of amount variable in the below code. </p>
  
  <pre><code>static void Insert(t_analysis* analysis)    
  {    
   _bstr_t strunitId;    
   _bstr_t strGdt=time(0);    
  _bstr_t strvalue;   
      std::string str;
  std::string commandStr = "insert into table1(unitid,g_time_dte_1,h_1,n_1,ch_1,co_1,im_1,ve_1,er_1) Values(123,'" + strGdt +"',";
      char tempBuf[50];
  for (int j = 0; j &lt; analysis-&gt;ubPeaksIntTab;j++ )
  {   
      sprintf(tempBuf, "%d", (analysis-&gt;peak + j)-&gt;amount);//here it takes the adrress of amount but not the value of amount variable.
      str += commandStr + tempBuf;
      if(j!=analysis-&gt;ubPeaksIntTab-1)
         commandStr += ",";
  }
  
  commandStr += ")";
  _ConnectionPtr pConn = NULL;
  
  try
  {       
      HRESULT hr = S_OK;
      CoInitialize(NULL);
      hr = pConn.CreateInstance((__uuidof(Connection)));
      _bstr_t strCon("Provider=SQLOLEDB;Dataq Source=MYPC\\SQLEXPRESS;Initial Catalog=keerth;User ID=sa;Password=password;Connect Timeout=30;");
  
      if(FAILED(hr))
      {
          printf("Error instantiating Connection object\n");
  
      }
  
      hr = pConn-&gt;Open(strCon,"sa","password",0);
  
      if(FAILED(hr))
      {
          printf("Error Opening Database object using ADO _ConnectionPtr \n");
  
      }
  
      //Execute the insert statement
      pConn-&gt;Execute(commandStr.c_str(), NULL,adExecuteNoRecords);
      pConn-&gt;Close();
  }
  catch(_com_error &amp;ce)
  {
      printf("Error:%s\n",ce.ErrorMessage());
      pConn-&gt;Close();
  }
  }
  </code></pre>
  
  <p>Whenever I run this getting the Error. Then I changed  the <code>char tempbuf[50];</code> to <code>std::string str1;</code>.<br>
  Now it is showing:</p>
  
  <pre><code>Error C2664: 'sprintf' : cannot convert parameter 1 from 'std::string' to 'char *;
  </code></pre>
  
  <p>The amount variable contains the float value.
  How can I copy the float value assign it to string variable?</p>