samedi 30 juillet 2016

Writing to stream using ternary operator ? in C++

I have several points of type double. I want to write them in the stream only when they are not 0. Also I have to say which one it is, like this: x1=" value " y1=" value " and so on.. Is there any way to do it like this: << ( (x1 != 0) ? ( "x1="" << x1 << '"' ) : ' ') ) << ( (y1 != 0) ? ( "y1="" << y1 << '"' ) : ' ') ) or I have to make several if else statements?

Aucun commentaire:

Enregistrer un commentaire