In my project, I need to combine doubles and lines into one line. There are several options for the above, but given the exact problems (I need to convert doubling with a certain accuracy), I decided to use std::stringstream. There are many places where I need this concatenation, so the accuracy setting for each conversion is not convenient (the accuracy used now may be changed in the future, or I can forget the accuracy setting somewhere).
I could define some function that creates an object stringstream, sets its accuracy and returns the created object, but I use C ++ 98, and there is no support for the copy constructor.
So, I decided to get from the class stringstream, as shown below, and only objects are used in my code stringstream:
class StringStream : public std::stringstream {
public:
StringStream(std::streamsize prec = 12) : std::stringstream() {
precision(prec);
}
};
And that does the job. But am I getting it right or is it a good way to implement what I need?
Or maybe there is a way to set the accuracy for boost::lexical_cast?
source
share