Serial.println for several variables separated by a space on a single line?

Juraj:
bit shift operator override. I never liked it

Me too - weird, right?

I wrote a simple utility library that allows you to use the streaming operators like in “normal” C++: Arduino PrintStream Library.

Your code would look like this:

[b][color=#d35400]  Serial[/color][/b] [color=#434f54]<<[/color] [color=#000000]gx[/color] [color=#434f54]<<[/color] [color=#00979c]' '[/color] [color=#434f54]<<[/color] [color=#000000]gy[/color] [color=#434f54]<<[/color] [color=#00979c]' '[/color] [color=#434f54]<<[/color] [color=#000000]gz[/color] [color=#434f54]<<[/color] [color=#000000]endl[/color][color=#000000];  [/color]

This will print the values of the three variables as expected.
Have a look at the example that demonstrates some more use cases.

Another useful “library” in my toolbox is the Arduino Debugging “library”. It has a couple of nice macros, for example:

  DEBUGVAL(gx, gy, gz);

This prints:

  gx = 0.00, gy = 0.00, gz = 0.00

Pieter

Edit: Seems like DBMcDonald beat me to it :slight_smile:

<< is just normal C stuff when outputting to stdin. Nothing weird really.

DBMcDonald:
<< is just normal C stuff when outputting to stdin. Nothing weird really.

But it looks weird. Why left shift?

DBMcDonald:
<< is just normal C stuff when outputting to stdin. Nothing weird really.

C++ only.

in language definition << and >> is a bit shift operator

AWOL:
But it looks weird. Why left shift?

Because you shove your text into the output stream. The output stream is on the left, so you “shift” all text to the left.
For input streams, you extract data from it, so you pull it out from left to right using “>>”.

Juraj:
in language definition << and >> is a bit shift operator

So? The language definition also defines operator<< and operator>> as the inserters and extractors for output and input streams.
(§30.7 in this document, for example)

Using these insertion operators is the standard if you’re doing any kind of desktop C++ where you have access to the standard library.

PieterP:
The output stream is on the left

On the left of what?

Why not use the carat symbol, and move it up?

Or plus for append? Or minus because it makes the line easier to read? Or asterisk because stars are cool? Or an ampersand to mean "this and that"? Or comma so it finally has a practical use?

I suspect the decision was primarily motivated by a drug induced hallucination. Or a dart thrown by a drunken monkey at a poster of C++ operators.

I like ampersand. That makes sense.

AWOL,
I truly think you're enjoying being contrary, but just in case ...
Please check std::basic_ostream<CharT,Traits>::operator<< - cppreference.com

We all know the "what". The question is "why".

DBMcDonald:
AWOL,
I truly think you're enjoying being contrary, but just in case ...
Please check std::basic_ostream<CharT,Traits>::operator<< - cppreference.com

No, I think you are being contrary by not posting a clickable link.

Seriously; why left shift?
Left shift is not any kind of insertion operator.
Why left? Why not right?

DBMcDonald:
<< is just normal C stuff when outputting to stdin.

Outputting to stdin is seriously weird.

Even calling it “cout” is off-putting.

AWOL,
It didn’t take you long to figure out I’m weird, but I really didn’t think following “so called” standard C++ coding practices from the “C++ Core Guidelines” made me THAT weird. If they’re good enough for “Bjarne Stroustrup”,
they’re good enough for me.

PS. These guidelines answer “Why”