title: C++ std::string length() or size() not working on method args
body: <p>I have a method that that creates a MatLab array name from a file path and returns it as a std::string. the resulting string is passed into another method that writes the name to the file. When I try to get the length of the passed in string, it displays 0 when the length of the string is 12 or 13 chars.</p>
  
  <p>My code:</p>
  
  <pre><code>bool MyClass::masterMethod(std::string fileURI){
  
   FILE* dataStream;
   // Assume dataStream is set up correctly
  
   // Get arrayName from File URI
   std::string arrayName = this-&gt;makeArrayNameFromPath( fileURI);
  
   //Write array name to file
   this-&gt;writeArrayName(arrayName , dataStream)
  
  
  
  }
  
  
  std::string MyClass::makeArrayNameFromPath(std::string filePathURI){
  
  
  std::string tempString = filePathURI.substr(filePathURI.find_last_of('/')+1); 
  
  std::string returnString = "";
  
  long index = 0;
  
  for(long i = 0; i &lt; tempString.length(); i++){
  
      if((tempString[i] != ' ') &amp;&amp; (tempString[i] != '.')){
  
          returnString[index++] = tempString[i];
      }
  }
  
  return returnString;
  
  }
  
  
  
  void MyClass::writeArrayName(std::string name , FILE *nameStream){
  
   // long testLength = name.length();
   // long testLength2 = name.size();
   // const char* testChar = nam.c_str();
   // long testCharLen = strlen(testChar);    
  
  // The size of the name is the number of Chars * sizeof(int8_t)
  int32_t sizeOfName = (int32_t)(name.length() * sizeof(int8_t));
  int32_t nameType = miINT8;
  
  fwrite(&amp;nameType , sizeof(int32_t) , 1 , nameStream);
  fwrite(&amp;sizeOfName, sizeof(sizeOfName), 1, nameStream);
  fwrite(&amp;name , sizeof(name[0]), sizeOfName , nameStream);   
  
  }
  </code></pre>
  
  <p>So I'm not sure why string::length is not working. If a create a std::string test = name,                          and print it , I can get the value of the string but can not get its length or size. 
  If I use const char* testName = name.c_str(); long test = strlen(testName), I get a the 
  correct value, but thought that wasn't necessary.</p>
  
  <p>So any advice or suggestion is appreciated.</p>