Print private/public key - c++

For testing purposes, I want to print my public and private key which are generated on the Arduino via elliptic curve.
The relevant code looks as follows,
#include <Ed25519.h>
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
uint8_t privateKey[32];
uint8_t publicKey[32];
Ed25519::generatePrivateKey(privateKey);
Ed25519::derivePublicKey(publicKey, privateKey);
Serial.println(publicKey);
Serial.print(",");
Serial.write(privateKey);
}
However, it gives me the following error:
/tmp/arduino_modified_sketch_961866/ask_receiver.pde: In function 'void setup()':
ask_receiver:52: error: call of overloaded 'println(uint8_t [32])' is ambiguous
Serial.println(publicKey);
^
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:5
2:29: note: candidates are:
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:78:12: note: size_t Print::println(const String&) <near match>
size_t println(const String &s);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:78:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const String&'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:79:12: note: size_t Print::println(const char*) <near match>
size_t println(const char[]);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:79:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const char*'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:80:12: note: size_t Print::println(char) <near match>
size_t println(char);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:80:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'char'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:81:12: note: size_t Print::println(unsigned char, int) <near match>
size_t println(unsigned char, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:81:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned char'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:82:12: note: size_t Print::println(int, int) <near match>
size_t println(int, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:82:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:83:12: note: size_t Print::println(unsigned int, int) <near match>
size_t println(unsigned int, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:83:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:84:12: note: size_t Print::println(long int, int) <near match>
size_t println(long, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:84:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:85:12: note: size_t Print::println(long unsigned int, int) <near match>
size_t println(unsigned long, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:85:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long unsigned int'
ask_receiver:54: error: call of overloaded 'write(uint8_t [32])' is ambiguous
Serial.write(privateKey);
^
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:54:28: note: candidates are:
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232:0,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:129:20: note: virtual size_t HardwareSerial::write(uint8_t) <near match>
virtual size_t write(uint8_t);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:129:20: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'uint8_t {aka unsigned char}'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:130:19: note: size_t HardwareSerial::write(long unsigned int) <near match>
inline size_t write(unsigned long n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:130:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:131:19: note: size_t HardwareSerial::write(long int) <near match>
inline size_t write(long n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:131:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:132:19: note: size_t HardwareSerial::write(unsigned int) <near match>
inline size_t write(unsigned int n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:132:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:133:19: note: size_t HardwareSerial::write(int) <near match>
inline size_t write(int n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:133:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'int'
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: size_t Print::write(const char*) <near match>
size_t write(const char *str) {
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const char*'
/tmp/arduino_modified_sketch_961866/ask_receiver.pde: In function 'void loop()':
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:80:51: warning: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
driver.printBuffer("Decrypted:", buf, strlen(buf));
^
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:25:0,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/avr/include/string.h:399:15: note: initializing argument 1 of 'size_t strlen(const char*)'
extern size_t strlen(const char *) __ATTR_PURE__;
^
exit status 1
call of overloaded 'println(uint8_t [32])' is ambiguous
I have also tried:
Serial.write((int)privateKey);
But it gives me gibberish output.
I also tried:
String stringOne = String(privateKey, HEX)
Serial.println(stringOne);
But it gives me the following output:
call of overloaded 'String(uint8_t [32], int)' is ambiguous
Preferably, I'd output it in HEX or some other value which I can transfer over another medium.

Solved it by using a simple for loop
uint8_t i;
for (i = 0; i < (uint8_t)(sizeof(privateKey)); i++) {
if (privateKey[i] < 0x10) { /* To print "0F", not "F" */
Serial.write('0');
}
Serial.print(privateKey[i], HEX);
}

Related

FABGL library esp32 arduino ide: Terminal.write error when using variables

Sorry for bother yours.
I was trying to do this:
Terminal.write("\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
Terminal.write("\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
Using variables in place of the constants, but this is impossible. I tried everything, but the Arduino esp32 compiler have the same error:
error: conversion from 'const uint8_t*' {aka 'const unsigned char*'} to 'const StringSumHelper' is ambiguous
Terminal.write((const uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: black, foreground: green
mmsj300:313:53: error: conversion from 'uint8_t*' {aka 'unsigned char*'} to 'const StringSumHelper' is ambiguous
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
I Have tried putting the (const uint8_t*) before the strings e etc, but nothing works... I see the implementation, but using (uint8_t*) also not working.
Can someone help me please ?
That cant be my fault, I need to know how to call the Terminal.write with variables, i do this in another's programs with another libraries all the times, and here are impossible..
PS: I have read all the examples, anyone have any consideration about use variables in the Terminal.write, only char (buf[i]), any time not have examples with strings variables.
Terminal.write definition:
size_t Terminal::write(const uint8_t * buffer, size_t size)
{
for (int i = 0; i < size; ++i)
write(*(buffer++));
return size;
}
please help me.
Complete Error Message:
mmsj300:313:53: error: conversion from 'uint8_t*' {aka 'unsigned char*'} to 'const StringSumHelper' is ambiguous
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:393:9: note: candidate: 'StringSumHelper::StringSumHelper(long long unsigned int)' <near match>
StringSumHelper(unsigned long long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:393:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long long unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:390:9: note: candidate: 'StringSumHelper::StringSumHelper(long long int)' <near match>
StringSumHelper(long long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:390:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long long int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:381:9: note: candidate: 'StringSumHelper::StringSumHelper(long unsigned int)' <near match>
StringSumHelper(unsigned long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:381:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:378:9: note: candidate: 'StringSumHelper::StringSumHelper(long int)' <near match>
StringSumHelper(long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:378:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:375:9: note: candidate: 'StringSumHelper::StringSumHelper(unsigned int)' <near match>
StringSumHelper(unsigned int num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:375:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:372:9: note: candidate: 'StringSumHelper::StringSumHelper(int)' <near match>
StringSumHelper(int num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:372:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:369:9: note: candidate: 'StringSumHelper::StringSumHelper(unsigned char)' <near match>
StringSumHelper(unsigned char num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:369:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'unsigned char' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:366:9: note: candidate: 'StringSumHelper::StringSumHelper(char)' <near match>
StringSumHelper(char c) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:366:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'char' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:363:9: note: candidate: 'StringSumHelper::StringSumHelper(const char*)' <near match>
StringSumHelper(const char *p) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:363:9: note: conversion of argument 1 would be ill-formed:
mmsj300:313:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'const char*' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:186:34: note: initializing argument 1 of 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
^~~~~~~~
mmsj300:314:52: error: conversion from 'uint8_t*' {aka 'unsigned char*'} to 'const StringSumHelper' is ambiguous
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:393:9: note: candidate: 'StringSumHelper::StringSumHelper(long long unsigned int)' <near match>
StringSumHelper(unsigned long long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:393:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long long unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:390:9: note: candidate: 'StringSumHelper::StringSumHelper(long long int)' <near match>
StringSumHelper(long long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:390:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long long int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:381:9: note: candidate: 'StringSumHelper::StringSumHelper(long unsigned int)' <near match>
StringSumHelper(unsigned long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:381:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:378:9: note: candidate: 'StringSumHelper::StringSumHelper(long int)' <near match>
StringSumHelper(long num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:378:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'long int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:375:9: note: candidate: 'StringSumHelper::StringSumHelper(unsigned int)' <near match>
StringSumHelper(unsigned int num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:375:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'unsigned int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:372:9: note: candidate: 'StringSumHelper::StringSumHelper(int)' <near match>
StringSumHelper(int num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:372:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'int' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:369:9: note: candidate: 'StringSumHelper::StringSumHelper(unsigned char)' <near match>
StringSumHelper(unsigned char num) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:369:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'unsigned char' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:366:9: note: candidate: 'StringSumHelper::StringSumHelper(char)' <near match>
StringSumHelper(char c) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:366:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'char' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:363:9: note: candidate: 'StringSumHelper::StringSumHelper(const char*)' <near match>
StringSumHelper(const char *p) :
^~~~~~~~~~~~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:363:9: note: conversion of argument 1 would be ill-formed:
mmsj300:314:24: error: invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'const char*' [-fpermissive]
Terminal.write((uint8_t*)"\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor to x, y
^~~~~~~~~~~~~~~
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h:186:34: note: initializing argument 1 of 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
^~~~~~~~
mmsj300:334:72: error: no matching function for call to 'fabgl::Terminal::write(StringSumHelper&)'
Terminal.write("\e[" + String(bcor) +";" + String(fcor) + "m"); // background: black, foreground: green
^
In file included from E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/fabgl.h:314,
from D:\Projetos\ESP32\MMSJ300\firmware\mmsj300\mmsj300.ino:27:
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate: 'virtual size_t fabgl::Terminal::write(const uint8_t*, size_t)'
size_t write(const uint8_t * buffer, size_t size);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate expects 2 arguments, 1 provided
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: candidate: 'virtual size_t fabgl::Terminal::write(uint8_t)'
size_t write(uint8_t c);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: no known conversion for argument 1 from 'StringSumHelper' to 'uint8_t' {aka 'unsigned char'}
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate: 'void fabgl::Terminal::write(uint8_t, bool)'
void write(uint8_t c, bool fromISR);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate expects 2 arguments, 1 provided
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Stream.h:26,
from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:166,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate: 'size_t Print::write(const char*, size_t)'
size_t write(const char *buffer, size_t size)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate expects 2 arguments, 1 provided
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: candidate: 'size_t Print::write(const char*)'
size_t write(const char *str)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: no known conversion for argument 1 from 'StringSumHelper' to 'const char*'
mmsj300:335:71: error: no matching function for call to 'fabgl::Terminal::write(StringSumHelper&)'
Terminal.write("\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor
^
In file included from E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/fabgl.h:314,
from D:\Projetos\ESP32\MMSJ300\firmware\mmsj300\mmsj300.ino:27:
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate: 'virtual size_t fabgl::Terminal::write(const uint8_t*, size_t)'
size_t write(const uint8_t * buffer, size_t size);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate expects 2 arguments, 1 provided
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: candidate: 'virtual size_t fabgl::Terminal::write(uint8_t)'
size_t write(uint8_t c);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: no known conversion for argument 1 from 'StringSumHelper' to 'uint8_t' {aka 'unsigned char'}
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate: 'void fabgl::Terminal::write(uint8_t, bool)'
void write(uint8_t c, bool fromISR);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate expects 2 arguments, 1 provided
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Stream.h:26,
from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:166,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate: 'size_t Print::write(const char*, size_t)'
size_t write(const char *buffer, size_t size)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate expects 2 arguments, 1 provided
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: candidate: 'size_t Print::write(const char*)'
size_t write(const char *str)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: no known conversion for argument 1 from 'StringSumHelper' to 'const char*'
mmsj300:343:72: error: no matching function for call to 'fabgl::Terminal::write(StringSumHelper&)'
Terminal.write("\e[" + String(fcor) +";" + String(bcor) + "m"); // background: black, foreground: green
^
In file included from E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/fabgl.h:314,
from D:\Projetos\ESP32\MMSJ300\firmware\mmsj300\mmsj300.ino:27:
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate: 'virtual size_t fabgl::Terminal::write(const uint8_t*, size_t)'
size_t write(const uint8_t * buffer, size_t size);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate expects 2 arguments, 1 provided
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: candidate: 'virtual size_t fabgl::Terminal::write(uint8_t)'
size_t write(uint8_t c);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1201:10: note: no known conversion for argument 1 from 'StringSumHelper' to 'uint8_t' {aka 'unsigned char'}
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate: 'void fabgl::Terminal::write(uint8_t, bool)'
void write(uint8_t c, bool fromISR);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1209:8: note: candidate expects 2 arguments, 1 provided
In file included from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Stream.h:26,
from C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:166,
from C:\Users\moahr\AppData\Local\Temp\arduino_build_152019\sketch\mmsj300.ino.cpp:1:
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate: 'size_t Print::write(const char*, size_t)'
size_t write(const char *buffer, size_t size)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:70:12: note: candidate expects 2 arguments, 1 provided
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: candidate: 'size_t Print::write(const char*)'
size_t write(const char *str)
^~~~~
C:\Users\moahr\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Print.h:62:12: note: no known conversion for argument 1 from 'StringSumHelper' to 'const char*'
mmsj300:344:71: error: no matching function for call to 'fabgl::Terminal::write(StringSumHelper&)'
Terminal.write("\e[" + String(vxx) + ";" + String(vyy) + "H"); // move cursor
^
In file included from E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/fabgl.h:314,
from D:\Projetos\ESP32\MMSJ300\firmware\mmsj300\mmsj300.ino:27:
E:\Program Files (x86)\Arduino\libraries\FabGL-master\src/terminal.h:1192:10: note: candidate: 'virtual size_t fabgl::Terminal::write(const uint8_t*, size_t)'
size_t write(const uint8_t * buffer, size_t size);
^~~~~
E:\Program Files (x86)\Arduino\libraries\FabGL-master\
You have two problems:
The first is that you should not cast any literal string. The StringSumHelper class have a const char * constructor that could be used, and literal strings will be converted to a const char * by default.
So doing e.g.
Terminal.write("\e[" + String(bcor) +";" + String(fcor) + "m"); // background: defined, foreground: defined
should work fine.
The second problem is that there's no proper Terminal::write function to use. You should declare (and define) it to use a String argument:
size_t Terminal::write(const String& string)
You could create this function as an overload that calls the variant with a pointer and a size:
size_t Terminal::write(const String& string)
{
return write(static_cast<const uint8_t*>(string.c_str()), string.length());
}
If Terminal inherits Print, this will work
Terminal.write(("\e[" + String(bcor) +";" + String(fcor) + "m").c_str());
Otherwise you have to put a message in a local variable
auto string = "\e[" + String(bcor) +";" + String(fcor) + "m";
Terminal.write(static_cast<const uint8_t*>(string.c_str()), string.length());
A solution is to use .c_str() like this:
// background: defined, foreground: defined
Terminal.write(("\e[" + String(bcor) +";" + String(fcor) + "m").c_str());
I do not like to use c_str(), but the only unique solution was this... until now.

Trying to create a universal map printer and this snippet won't compile (Issue with ADL?) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
Here is the full program.
I'm using clang 13 with -std=c++20 -stdlib=libc++.
The error message, not included here because it's extremely long, basically says that the compiler does not even consider the operator<< function I've included here (error is on the std::cerr line near the end of the snippet).
#include <iostream>
#include <string>
#include <unordered_map>
template<typename K, typename V, typename ...Args>
std::ostream& operator<<(std::ostream& os, std::unordered_map<K, V, Args...> const& o) noexcept
{
for (auto const& [k, v] : o)
os << " " << k << ": " << v;
return os;
}
namespace my_namespace
{
struct A
{
std::unordered_map<int, std::string> map{{1, "hello"}, {2, "goodbye"}};
};
A a;
}
int main()
{
std::cerr << my_namespace::a; // error is here
}
Here is the lengthy error message (sorry for not including it earlier):
file.cpp:25:15: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'A')
std::cerr << a;
~~~~~~~~~ ^ ~
/usr/lib/llvm-13/bin/../include/c++/v1/cstddef:141:3: note: candidate function template not viable: no known conversion from 'std::ostream' (aka 'basic_ostream<char>') to 'std::byte' for 1st argument
operator<< (byte __lhs, _Integer __shift) noexcept
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:748:1: note: candidate function template not viable: no known conversion from 'A' to 'char' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:781:1: note: candidate function template not viable: no known conversion from 'A' to 'char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, char __c)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:788:1: note: candidate function template not viable: no known conversion from 'A' to 'signed char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:795:1: note: candidate function template not viable: no known conversion from 'A' to 'unsigned char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:809:1: note: candidate function template not viable: no known conversion from 'A' to 'const char *' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:855:1: note: candidate function template not viable: no known conversion from 'A' to 'const char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:862:1: note: candidate function template not viable: no known conversion from 'A' to 'const signed char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:870:1: note: candidate function template not viable: no known conversion from 'A' to 'const unsigned char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1055:1: note: candidate function template not viable: no known conversion from 'A' to 'const std::error_code' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:741:1: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'A')
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
^
/usr/lib/llvm-13/bin/../include/c++/v1/__random/uniform_int_distribution.h:282:1: note: candidate template ignored: could not match 'uniform_int_distribution<type-parameter-0-2>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:802:1: note: candidate template ignored: could not match 'const _CharT *' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1038:1: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1046:1: note: candidate template ignored: could not match 'basic_string_view<type-parameter-0-0, type-parameter-0-1>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1063:1: note: candidate template ignored: could not match 'shared_ptr<type-parameter-0-2>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1082:1: note: candidate template ignored: could not match 'bitset<_Size>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
^
file.cpp:6:15: note: candidate template ignored: could not match 'unordered_map<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2...>' against 'A'
std::ostream& operator<<(std::ostream& os, std::unordered_map<K, V, Args...> const& o) noexcept
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1030:11: note: candidate template ignored: requirement 'integral_constant<bool, false>::value' was not satisfied [with _Stream = std::ostream &, _Tp = A]
_Stream&& operator<<(_Stream&& __os, const _Tp& __x)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:1075:1: note: candidate template ignored: could not match 'unique_ptr<type-parameter-0-2, type-parameter-0-3>' against 'A'
operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:188:20: note: candidate function not viable: no known conversion from 'A' to 'std::ostream &(*)(std::ostream &)' for 1st argument
basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:192:20: note: candidate function not viable: no known conversion from 'A' to 'basic_ios<std::basic_ostream<char>::char_type, std::basic_ostream<char>::traits_type> &(*)(basic_ios<std::basic_ostream<char>::char_type, std::basic_ostream<char>::traits_type> &)' (aka 'basic_ios<char, std::char_traits<char>> &(*)(basic_ios<char, std::char_traits<char>> &)') for 1st argument
basic_ostream& operator<<(basic_ios<char_type, traits_type>&
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:197:20: note: candidate function not viable: no known conversion from 'A' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument
basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:200:20: note: candidate function not viable: no known conversion from 'A' to 'bool' for 1st argument
basic_ostream& operator<<(bool __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:201:20: note: candidate function not viable: no known conversion from 'A' to 'short' for 1st argument
basic_ostream& operator<<(short __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:202:20: note: candidate function not viable: no known conversion from 'A' to 'unsigned short' for 1st argument
basic_ostream& operator<<(unsigned short __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:203:20: note: candidate function not viable: no known conversion from 'A' to 'int' for 1st argument
basic_ostream& operator<<(int __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:204:20: note: candidate function not viable: no known conversion from 'A' to 'unsigned int' for 1st argument
basic_ostream& operator<<(unsigned int __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:205:20: note: candidate function not viable: no known conversion from 'A' to 'long' for 1st argument
basic_ostream& operator<<(long __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:206:20: note: candidate function not viable: no known conversion from 'A' to 'unsigned long' for 1st argument
basic_ostream& operator<<(unsigned long __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:207:20: note: candidate function not viable: no known conversion from 'A' to 'long long' for 1st argument
basic_ostream& operator<<(long long __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:208:20: note: candidate function not viable: no known conversion from 'A' to 'unsigned long long' for 1st argument
basic_ostream& operator<<(unsigned long long __n);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:209:20: note: candidate function not viable: no known conversion from 'A' to 'float' for 1st argument
basic_ostream& operator<<(float __f);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:210:20: note: candidate function not viable: no known conversion from 'A' to 'double' for 1st argument
basic_ostream& operator<<(double __f);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:211:20: note: candidate function not viable: no known conversion from 'A' to 'long double' for 1st argument
basic_ostream& operator<<(long double __f);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:212:20: note: candidate function not viable: no known conversion from 'A' to 'const void *' for 1st argument; take the address of the argument with &
basic_ostream& operator<<(const void* __p);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:213:20: note: candidate function not viable: no known conversion from 'A' to 'basic_streambuf<std::basic_ostream<char>::char_type, std::basic_ostream<char>::traits_type> *' (aka 'basic_streambuf<char, std::char_traits<char>> *') for 1st argument
basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
^
/usr/lib/llvm-13/bin/../include/c++/v1/ostream:216:20: note: candidate function not viable: no known conversion from 'A' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
basic_ostream& operator<<(nullptr_t)
^
1 error generated.
You have provided operator<< for a wrong type there. You gave for the std::unordered_map not for the my_namespace::A. Hence, the compiler can not find a operator<< for my_namespace::A.
You need instead
namespace my_namespace
{
// ...
std::ostream& operator<<(std::ostream& os, A const& a) noexcept
// ^^^^^^^^^^^^
{
for (auto const& [k, v] : a.map)
os << " " << k << ": " << v;
return os;
}
}
See demo
You overload operator<< for std::unordered_map<int, std::string> but not my_namespace::A here.
One way is to overload it for my_namespace::A.
std::ostream& operator<<(std::ostream& os, const A& a) noexcept
{
for (auto const& [k, v] : a.map)
os << " " << k << ": " << v;
return os;
}
Another way is to make A can be implicitly converted to std::unordered_map<int, std::string>.
struct A
{
A() {}
std::unordered_map<int, std::string> map{{1, "hello"}, {2, "goodbye"}};
operator std::unordered_map<int, std::string>() const {
return map;
}
};

C++ Arduino Vector issues with mismatched types?

I've been trying to write some effects for a strip of RGB LEDs to be controlled via an Arduino Uno R3. For context, I'm working on the animation of a ball (a set of 5 LEDs) moving backwards and forward along the strip, bouncing from time to time.
The vector causing issue is the Colour object, which I want to be a vector of CRGB colours which, when fewer than the number of colours available are passed to the function, it simply uses the first x amount but if there are more balls than there are colours then it should simply re-use them.
Apologies if there are any errors in my formatting and such.
The issue is when I try to pass the vectors as constructors to BouncingBallEffect it gives the following error:
[File-Path]\sketch_jul20b\sketch_jul20b.ino: In constructor 'BouncingBallEffect::BouncingBallEffect(size_t, size_t, byte, bool)':
sketch_jul20b:44:28: error: no matching function for call to 'Vector<double>::Vector(size_t&)'
Colours(ballCount)
^
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: candidate: template<unsigned int MAX_SIZE> Vector<T>::Vector(T (&)[MAX_SIZE], size_t)
Vector(T (&values)[MAX_SIZE],
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: template argument deduction/substitution failed:
[File-Path]\sketch_jul20b\sketch_jul20b.ino:44:28: note: mismatched types 'double [MAX_SIZE]' and 'size_t {aka unsigned int}'
Colours(ballCount)
^
In file included from [File-Path]\Vector-1.2.1\src/Vector.h:95:0,
from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate: Vector<T>::Vector() [with T = double]
Vector<T>::Vector()
^~~~~~~~~
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate expects 0 arguments, 1 provided
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(const Vector<double>&)
class Vector
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'const Vector<double>&'
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(Vector<double>&&)
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'Vector<double>&&'
sketch_jul20b:44:28: error: no matching function for call to 'Vector<double>::Vector(size_t&)'
Colours(ballCount)
^
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: candidate: template<unsigned int MAX_SIZE> Vector<T>::Vector(T (&)[MAX_SIZE], size_t)
Vector(T (&values)[MAX_SIZE],
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: template argument deduction/substitution failed:
[File-Path]\sketch_jul20b\sketch_jul20b.ino:44:28: note: mismatched types 'double [MAX_SIZE]' and 'size_t {aka unsigned int}'
Colours(ballCount)
^
In file included from [File-Path]\Vector-1.2.1\src/Vector.h:95:0,
from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate: Vector<T>::Vector() [with T = double]
Vector<T>::Vector()
^~~~~~~~~
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate expects 0 arguments, 1 provided
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(const Vector<double>&)
class Vector
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'const Vector<double>&'
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(Vector<double>&&)
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'Vector<double>&&'
sketch_jul20b:44:28: error: no matching function for call to 'Vector<double>::Vector(size_t&)'
Colours(ballCount)
^
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: candidate: template<unsigned int MAX_SIZE> Vector<T>::Vector(T (&)[MAX_SIZE], size_t)
Vector(T (&values)[MAX_SIZE],
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: template argument deduction/substitution failed:
[File-Path]\sketch_jul20b\sketch_jul20b.ino:44:28: note: mismatched types 'double [MAX_SIZE]' and 'size_t {aka unsigned int}'
Colours(ballCount)
^
In file included from [File-Path]\Vector-1.2.1\src/Vector.h:95:0,
from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate: Vector<T>::Vector() [with T = double]
Vector<T>::Vector()
^~~~~~~~~
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate expects 0 arguments, 1 provided
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(const Vector<double>&)
class Vector
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'const Vector<double>&'
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(Vector<double>&&)
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'Vector<double>&&'
sketch_jul20b:44:28: error: no matching function for call to 'Vector<double>::Vector(size_t&)'
Colours(ballCount)
^
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: candidate: template<unsigned int MAX_SIZE> Vector<T>::Vector(T (&)[MAX_SIZE], size_t)
Vector(T (&values)[MAX_SIZE],
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: template argument deduction/substitution failed:
[File-Path]\sketch_jul20b\sketch_jul20b.ino:44:28: note: mismatched types 'double [MAX_SIZE]' and 'size_t {aka unsigned int}'
Colours(ballCount)
^
In file included from [File-Path]\Vector-1.2.1\src/Vector.h:95:0,
from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate: Vector<T>::Vector() [with T = double]
Vector<T>::Vector()
^~~~~~~~~
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate expects 0 arguments, 1 provided
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(const Vector<double>&)
class Vector
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'const Vector<double>&'
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<double>::Vector(Vector<double>&&)
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'Vector<double>&&'
sketch_jul20b:44:28: error: no matching function for call to 'Vector<CRGB>::Vector(size_t&)'
Colours(ballCount)
^
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: candidate: template<unsigned int MAX_SIZE> Vector<T>::Vector(T (&)[MAX_SIZE], size_t)
Vector(T (&values)[MAX_SIZE],
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:24:3: note: template argument deduction/substitution failed:
[File-Path]\sketch_jul20b\sketch_jul20b.ino:44:28: note: mismatched types 'CRGB [MAX_SIZE]' and 'size_t {aka unsigned int}'
Colours(ballCount)
^
In file included from [File-Path]\Vector-1.2.1\src/Vector.h:95:0,
from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate: Vector<T>::Vector() [with T = CRGB]
Vector<T>::Vector()
^~~~~~~~~
[File-Path]\Vector-1.2.1\src/Vector/VectorDefinitions.h:16:1: note: candidate expects 0 arguments, 1 provided
In file included from [File-Path]\sketch_jul20b\sketch_jul20b.ino:6:0:
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<CRGB>::Vector(const Vector<CRGB>&)
class Vector
^~~~~~
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'const Vector<CRGB>&'
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: candidate: constexpr Vector<CRGB>::Vector(Vector<CRGB>&&)
[File-Path]\Vector-1.2.1\src/Vector.h:19:7: note: no known conversion for argument 1 from 'size_t {aka unsigned int}' to 'Vector<CRGB>&&'
My code is here:
#include <Arduino.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
using namespace std;
#include <Vector.h>
static const CRGB ballColours [] = {
CRGB::Green,
CRGB::Red,
CRGB::Blue,
CRGB::Orange,
CRGB::Indigo
};
class BouncingBallEffect {
private:
double InitialBallSpeed(double height) const {
return sqrt(-2 * Gravity * height); // Because MATH!
}
size_t _cLength;
size_t _cBalls;
byte _fadeRate;
bool _bMirrored;
const double Gravity = -9.81; // Because PHYSICS!
const double StartHeight = 1; // Drop balls from max height initially
Vector<double> ClockTimeAtLastBounce, Height, BallSpeed, Dampening;
Vector<CRGB> Colours;
public:
// BouncingBallEffect
//
// Caller specs strip length, number of balls, persistence level (255 is least), and whether the
// balls should be drawn mirrored from each side.
BouncingBallEffect(size_t cLength, size_t ballCount = 3, byte fade = 0, bool bMirrored = false)
: _cLength(cLength - 1),
_cBalls(ballCount),
_fadeRate(fade),
_bMirrored(bMirrored),
ClockTimeAtLastBounce(ballCount),
Height(ballCount),
BallSpeed(ballCount),
Dampening(ballCount),
Colours(ballCount)
{
for (size_t i = 0; i < ballCount; i++) {
Height[i] = StartHeight; // Current Ball Height
Dampening[i] = 0.90 - i / pow(_cBalls, 2); // Bounciness of this ball
BallSpeed[i] = InitialBallSpeed(Height[i]); // Don't dampen initial launch
}
}
};
Any help anyone can offer would be much appreciated, thank you.
Arduino's Vector library (https://github.com/janelia-arduino/Vector) accepts a statically allocated array at construction time, unlike std::vector which you can pass a size_t into.
template <typename T>
class Vector
{
public:
Vector();
template <size_t MAX_SIZE>
Vector(T (&values)[MAX_SIZE],
size_t size=0);
// ...
};
You will need to pass an array instead of a size_t, or use a different data structure during these member initializers:
// ...
ClockTimeAtLastBounce(ballCount),
Height(ballCount),
BallSpeed(ballCount),
Dampening(ballCount),
Colours(ballCount)

Am I Using Stringstream Wrong?

I have a program that compiles in XCode. In that program, I am taking advantage of stringstream's ability to store values according to the type that they are being assigned to.
Eg) The user inputs a letter, a number, and a symbol separated by spaces in the console. I make a call to getline that gets all three values and stores them in a string. I then create a stringstream with that string's data and assign the values to some variables, a char, an int, and a char in this case. I compile and run within XCode and this works. Then, I take that same file in a terminal and call g++ -o executableName fileName.cpp. Here, I get an error.
Working Example:
main.cpp
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
string buffer;
char letter;
int number;
char symbol;
cout << "Enter (letter) (number) (symbol): ";
getline(cin, buffer);
stringstream(buffer) >> letter >> number >> symbol; //The error occurs here
cout << letter << " " << number << " " << symbol << endl;
return 0;
}
I compile and run in XCode:
Enter (letter) (number) (symbol): B 145 #
B 145 #
Program ended with exit code: 0
I compile with g++:
$ g++ -o test main.cpp
main.cpp:14:26: error: invalid operands to binary expression ('std::__1::stringstream' (aka 'basic_stringstream<char>') and 'int')
stringstream(buffer) >> letter >> number >> symbol;
~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~
and then follows all of this:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:789:1: note: candidate function not viable: no known conversion from 'char' to 'unsigned char ' for 2nd
argument
operator>>(basic_istream& __is, unsigned char __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:797:1: note: candidate function not viable: no known conversion from 'char' to 'signed char ' for 2nd
argument
operator>>(basic_istream& __is, signed char __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:804:1: note: candidate function [with _CharT = char, _Traits = std::__1::char_traits] not viable:
no known conversion from 'std::__1::stringstream' (aka 'basic_stringstream') to 'basic_istream > &' for 1st argument
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:832:1: note: candidate function not viable: no known conversion from 'char' to 'unsigned char &' for 2nd
argument
operator>>(basic_istream& __is, unsigned char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:840:1: note: candidate function not viable: no known conversion from 'char' to 'signed char &' for 2nd
argument
operator>>(basic_istream& __is, signed char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:220:20: note: candidate function not viable: no known conversion from 'char' to
'std::__1::basic_istream &()(std::__1::basic_istream &)' for 1st argument
basic_istream& operator>>(basic_istream& (__pf)(basic_istream&))
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:224:20: note: candidate function not viable: no known conversion from 'char' to
'basic_ios >::char_type, std::__1::basic_istream >::traits_type> &()(basic_ios >::char_type, std::__1::basic_istream >::traits_type> &)' (aka 'basic_ios > &()(basic_ios > &)') for 1st argument
basic_istream& operator>>(basic_ios&
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:229:20: note: candidate function not viable: no known conversion from 'char' to
'std::__1::ios_base &()(std::__1::ios_base &)' for 1st argument
basic_istream& operator>>(ios_base& (__pf)(ios_base&))
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:232:20: note: candidate function not viable: no known conversion from 'char' to
'basic_streambuf >::char_type, std::__1::basic_istream >::traits_type> *'
(aka 'basic_streambuf > ') for 1st argument
basic_istream& operator>>(basic_streambuf __sb);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:233:20: note: candidate function not viable: no known conversion from 'char' to 'bool &' for 1st argument
basic_istream& operator>>(bool& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:234:20: note: candidate function not viable: no known conversion from 'char' to 'short &' for 1st
argument
basic_istream& operator>>(short& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:235:20: note: candidate function not viable: no known conversion from 'char' to 'unsigned short &' for
1st argument
basic_istream& operator>>(unsigned short& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:236:20: note: candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument
basic_istream& operator>>(int& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:237:20: note: candidate function not viable: no known conversion from 'char' to 'unsigned int &' for 1st
argument
basic_istream& operator>>(unsigned int& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:238:20: note: candidate function not viable: no known conversion from 'char' to 'long &' for 1st argument
basic_istream& operator>>(long& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:239:20: note: candidate function not viable: no known conversion from 'char' to 'unsigned long &' for 1st
argument
basic_istream& operator>>(unsigned long& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:240:20: note: candidate function not viable: no known conversion from 'char' to 'long long &' for 1st
argument
basic_istream& operator>>(long long& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:241:20: note: candidate function not viable: no known conversion from 'char' to 'unsigned long long &'
for 1st argument
basic_istream& operator>>(unsigned long long& __n);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:242:20: note: candidate function not viable: no known conversion from 'char' to 'float &' for 1st
argument
basic_istream& operator>>(float& __f);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:243:20: note: candidate function not viable: no known conversion from 'char' to 'double &' for 1st
argument
basic_istream& operator>>(double& __f);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:244:20: note: candidate function not viable: no known conversion from 'char' to 'long double &' for 1st
argument
basic_istream& operator>>(long double& __f);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:245:20: note: candidate function not viable: no known conversion from 'char' to 'void &' for 1st
argument
basic_istream& operator>>(void& __p);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:740:1: note: candidate template ignored: could not match '_CharT ' against 'char'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1506:1: note: candidate template ignored: could not match 'basic_string' against 'char'
operator>>(basic_istream<_CharT, _Traits>& __is,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1638:1: note: candidate template ignored: could not match 'bitset<_Size>' against 'char'
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
^
1 error generated.
Is my use of stringstream wrong? (as an aside, Why does XCode allow the code to compile while g++ does not? I thought XCode uses the same g++)

What does std::cout << std::cin do?

I am new to C++ and was messing around with some of the things that I've learnt.
So I tried the following code:
#include <iostream>
int main() {
std::cout << std::cin;
}
So I expected the code to return an error, but instead got what I think is a memory address (0x6fccc408). Also, when running it multiple times, I got the same memory address, even after restarting cmd. What exactly does this memory address signify?
It looks like you are using C++98 or C++03. In those versions cin could be implicitly converted to a void* so what you are seeing is that conversion.
If you used C++11, which got rid of the implicit void* conversion and instead implemented a explicit conversion to bool this would produce a compiler error like
clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
main.cpp:4:15: error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'istream' (aka 'basic_istream<char>'))
std::cout << std::cin;
~~~~~~~~~ ^ ~~~~~~~~
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:245:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const void *' for 1st argument; take the address of the argument with &
operator<<(const void* __p)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/system_error:209:5: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const std::error_code' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:108:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to '__ostream_type &(*)(__ostream_type &)' (aka 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &)') for 1st argument
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:117:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to '__ios_type &(*)(__ios_type &)' (aka 'basic_ios<char, std::char_traits<char> > &(*)(basic_ios<char, std::char_traits<char> > &)') for 1st argument
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:127:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'std::ios_base &(*)(std::ios_base &)' for 1st argument
operator<<(ios_base& (*__pf) (ios_base&))
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:166:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'long' for 1st argument
operator<<(long __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:170:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'unsigned long' for 1st argument
operator<<(unsigned long __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:174:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'bool' for 1st argument
operator<<(bool __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:178:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'short' for 1st argument
operator<<(short __n);
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:181:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'unsigned short' for 1st argument
operator<<(unsigned short __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:189:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'int' for 1st argument
operator<<(int __n);
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:192:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'unsigned int' for 1st argument
operator<<(unsigned int __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:201:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'long long' for 1st argument
operator<<(long long __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:205:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'unsigned long long' for 1st argument
operator<<(unsigned long long __n)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:220:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'double' for 1st argument
operator<<(double __f)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:224:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'float' for 1st argument
operator<<(float __f)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:232:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'long double' for 1st argument
operator<<(long double __f)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:270:7: note: candidate function not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to '__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument
operator<<(__streambuf_type* __sb);
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:502:5: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'char' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:508:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, char __c)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:514:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'signed char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:519:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'unsigned char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:556:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:569:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const signed char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:574:5: note: candidate function [with _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const unsigned char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:628:5: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>, _Tp = std::basic_istream<char>] not viable: no known conversion from 'ostream' (aka 'basic_ostream<char>') to 'basic_ostream<char, std::char_traits<char> > &&' for 1st argument
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/bits/ostream.tcc:321:5: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no known conversion from 'istream' (aka 'basic_istream<char>') to 'const char *' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:497:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'std::basic_istream<char>')
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/bits/basic_string.h:5325:5: note: candidate template ignored: could not match 'basic_string' against 'basic_istream'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../include/c++/6.1.0/ostream:539:5: note: candidate template ignored: could not match 'const _CharT *' against 'istream' (aka 'basic_istream<char>')
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
^
1 error generated.