I am seeing some strange behavior with HP-UX 11.11 and aCC A.3.xx
compilers. Here is the test code:
#include <stdlib.h>
#include <string>
#include <iostream>
using std::cout;
using std::endl;
using std::flush;
int main()
{
long lng1 = 1000;
long lng2 = 2000;
cout << "lng1 is " << lng1 << endl;
cout << "lng2 is " << lng2 << endl;
// cout << "lng2 is " << ltoa(lng2) << endl;
std::string s = std::string("lng1 = ")+ltoa(lng1)+", lng2 =
"+ltoa(lng2);
cout<<s<<endl<<endl<<flush;
return 0;
}
This is the output:
lng1 is 1000
lng2 is 2000
lng1 = 1000, lng2 = 1000
Notice that the lng2 value is 1000 instead of 2000 when used with +ltoa.
Now, uncomment the line
cout << "lng2 is " << ltoa(lng2) << endl;
This is the output:
lng1 is 1000
lng2 is 2000
lng2 is 2000
lng1 = 1000, lng2 = 2000
Notice that the lng2 value is now displayed as 2000 when used with
+ltoa.
Is this a problem with the + operator in std::string? The ltoa seems to
work okay by itself. Why does adding the line cout << "lng2 is " <<
ltoa(lng2) << endl; make the +ltoa display the correct value?
Craig Chariton