[stl] ohserialstream cout(Serial), [solved (ish)]

The only problem is std::ohserialstream cout(Serial), the compiler gives errors that sounds like an operator should be overloaded. I’m not familiar enough with c++ to understand what to do when I see this kind of error.

info: I got the -std=c++11 flag activated. My goal is for ohserialstream to work correctly.

Code used: GitHub - maniacbug/StandardCplusplus: Standard C++ for Arduino (port of uClibc++)
This is taken from the example, I’ve commented out the irrelevant rows.

#include <StandardCplusplus.h>
#include <serstream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

namespace std
{
  ohserialstream cout(Serial);
}

vector<string> strings;

void setup(void)
{
  Serial.begin(57600);

  strings.push_back("Hello,");
  strings.push_back("world!");
  //copy(strings.begin(),strings.end(),ostream_iterator<string>(cout," "));
  //cout << endl;
}

void loop(void)
{
}

The error:

Arduino: 1.6.0 (Windows 7), Board: "Arduino Leonardo"

string_vector.ino:13:29: error: no matching function for call to 'std::basic_oserialstream<char>::basic_oserialstream(Serial_&)'
string_vector.ino:13:29: note: candidates are:
In file included from string_vector.ino:2:0:
C:\Users\<name>\Documents\Arduino\libraries\maniac/serstream:230:12: note: std::basic_oserialstream<charT, traits, Tserial>::basic_oserialstream(Tserial&) [with charT = char; traits = std::char_traits<char>; Tserial = HardwareSerial]
    : basic_ios<charT, traits>(&sb), basic_ostream<charT,traits>(&sb), sb(serial_,ios_base::out)

            ^
C:\Users\<name>\Documents\Arduino\libraries\maniac/serstream:230:12: note:   no known conversion for argument 1 from 'Serial_' to 'HardwareSerial&'
C:\Users\<name>\Documents\Arduino\libraries\maniac/serstream:213:60: note: std::basic_oserialstream<char>::basic_oserialstream(const std::basic_oserialstream<char>&)
   : public basic_ostream<charT,traits>

                                                            ^
C:\Users\<name>\Documents\Arduino\libraries\maniac/serstream:213:60: note:   no known conversion for argument 1 from 'Serial_' to 'const std::basic_oserialstream<char>&'
Error compiling.

I’ve tried my best solving it on my own… sadly that’s not good enough.

Bump...

Please someone help with this one ;_;

thank you,

Matt

I got a slightly modified version to compile without errors:

#include <serstream>
#include <string>
#include <vector>
#include <iterator>
#include <pnew.cpp>

using namespace std;

namespace std
{
  ohserialstream cout(Serial);
}

vector<string> strings;

void setup(void)
{
  Serial.begin(115200);

  strings.push_back("Hello,");
  strings.push_back("world!");
  copy(strings.begin(),strings.end(),ostream_iterator<string>(cout," "));
  cout << endl;
}

void loop(void) { }

Output:

Hello, world!

However I used the STL library described here which I obtained from The Standard Template Library (STL) for AVR with C++ streams.

That's where I went first and it kind of worked.. but only with arduino ide version 1.0.6 which compiles with the -std=c++98 flag (or no -std=c++11 flag as if it was c++98 code)

And I want the -std=c++11 flag which requires me to use arduino ide version 1.6.0 (because there's a platform.txt file which I can add the flag to, in 1.0.6 the file doesn't exist), which arduino ide version are you using gammon?

I tested with 1.0.6, but I can try a later version. I’ll get back to you.

I got it to compile under IDE 1.6.0 after making two more changes which are now documented on my page http://www.gammon.com.au/forum/?id=11119.

However there is something else wrong because it just prints "He" instead of "Hello, world!".

I suspect a problem with memory allocation.

All I can suggest at this stage is using IDE 1.0.6.

Thank you Gammon for looking into my problem, I greatly appreciate it!

One can only hope that someone shall find that memory leak :p

Another one can also hope for arduino to start using the -std=c++11 flag as a standard (c++14 is out now, I mean come on :/ )

Huge thanks!