I am writing some data loader libraries and I am sticking to standard libraries to make them as portable as possible, just in-case we want to utilize the loaders outside of a Qt environment. I am building a std::string with the file header information in a function called string DataType::getHeaderString( ).

Qt Code:
  1. string DataType::getHeaderString( )
  2. {
  3. ostringstream collection,
  4. segment,
  5. altitude,
  6. longitude,
  7. latitude;
  8.  
  9. string hdr;
  10.  
  11. hdr += string("Timestamp: ") + mTimestamp + string("\n");
  12.  
  13. hdr += string("Description: ") + mDesc + string("\n");
  14.  
  15. collection << mCollectionNumber;
  16. hdr += string("Collection Number: ") + collection.str( ) + string("\n");
  17.  
  18. segment << mSegmentNumber;
  19. hdr += string("Segment Number: ") + segment.str( ) + string("\n");
  20.  
  21. altitude << mLocation.altitude;
  22. hdr += string("Location:\n Altitude: ") + altitude.str( ) + string("\n");
  23.  
  24. latitude << mLocation.latitude;
  25. hdr += string(" Latitude: ") + latitude.str( ) + string("\n");
  26.  
  27. longitude << mLocation.longitude;
  28. hdr += string(" Longitude: ") + longitude.str( ) + string("\n");
  29.  
  30. hdr += string("Data Type: ") + mDataType + string("\n");
  31.  
  32. return hdr;
  33. }
To copy to clipboard, switch view to plain text mode 

Immediatly after calling this function
Qt Code:
  1. string hdrStr( data.getHeaderString( ) );
To copy to clipboard, switch view to plain text mode 
, Visual Studios 2003 returns a "Invalid Heap Pointer" exception and aborts. I was reading in forums to pass the string as a reference argument:
Qt Code:
  1. void DataType::getHeaderString( string &hdr )
  2. {
  3. ostringstream collection,
  4. segment,
  5. altitude,
  6. longitude,
  7. latitude;
  8.  
  9. hdr += string("Timestamp: ") + mTimestamp + string("\n");
  10.  
  11. hdr += string("Description: ") + mDesc + string("\n");
  12.  
  13. collection << mCollectionNumber;
  14. hdr += string("Collection Number: ") + collection.str( ) + string("\n");
  15.  
  16. segment << mSegmentNumber;
  17. hdr += string("Segment Number: ") + segment.str( ) + string("\n");
  18.  
  19. altitude << mLocation.altitude;
  20. hdr += string("Location:\n Altitude: ") + altitude.str( ) + string("\n");
  21.  
  22. latitude << mLocation.latitude;
  23. hdr += string(" Latitude: ") + latitude.str( ) + string("\n");
  24.  
  25. longitude << mLocation.longitude;
  26. hdr += string(" Longitude: ") + longitude.str( ) + string("\n");
  27.  
  28. hdr += string("Data Type: ") + mDataType + string("\n");
  29.  
  30. return hdr;
  31. }
To copy to clipboard, switch view to plain text mode 
but I receive the same error when I reach the end of the scope of the string.

Qt Code:
  1. {
  2. string hdrStr;
  3.  
  4. data.getHeaderString( hdrString );
  5. } // Error occurs after brace
To copy to clipboard, switch view to plain text mode 

I am really at a loss as to why this is occuring. I have used strings before in this fashion on Linux and VS 6.0 without any problems. Any suggestions?

Thanks!