简体   繁体   中英

configure linux out streams

There is an issue in Linux, that it has 0 and -0 . This is because of Floating points, etc. I want to always ignore the - before the 0 .

Is there a way to configure the 'out stream' (to a file) or the working IDE/editor?

thank you

If you are using C++, you may be able to create your own stream formatter specialization:

Something like

class my_ostream : public std::ostream {
public:
  my_ostream& operator<<( float f ) {
     std::ostrstream oss;
     oss << f;
     if( oss.str() == "-0" ) f = fabs(f);
     *this->std::ostream << f;
     return *this;
  }
};

You probably need to copy formatting from *this to the ostringstream.

Note that I have created a wrapper type. You might be able simply to overload a specialization for

std::ostream& operator(<< std::ostream& os, float f ) 

and similarly for doubles, and other float types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM