0

EDIT: Actually, while we are at it, I need to do the same thing for a double as well - I have something NNNDD in the middle of a const char*, where the N's are the whole part and the D's are the decimal (so in 123.45 would appear as a const char* to 12345). I know how many whole numbers I'll have, and I know how many decimals, so it's just a matter of getting a fraction out of them.

I have a const char* somewhere in the middle of there is a time sequence of the format HHMMSSMMM (hours, minutes, seconds, milliseconds). I would like to create a ptime out of it (I know where the sequence begins, so I have a const char* to its start). Is there a good, efficient way to do this? Right now I am extracting each time unit value, storing them in local variables, and calling the ptime constructor with a default boost::gregorian::date() and a time_duration of hours(hh) + minutes(mm) + seconds(ss) + milliseconds(mmm)... but it feels kind of clumsy, roundabout. Shouldn't I be able just pass a time string and not worry about the date?

Argent
  • 795
  • 2
  • 7
  • 25

1 Answers1

0

For the doubles, insert a . and then read it into a double.

 const char * pDoubleString = ...;
 const long DoubleStringLength = ...;
 const long DoubleWholeCharCount = ...;

 std::string DoubleAsString = std::string(pDoubleString, DoubleStringLength);
 DoubleAsString.Insert(DoubleWholeCharCount, ".");
 double DoubleValue = std::atof(DoubleAsString.c_str());
lcs
  • 4,227
  • 17
  • 36