I would like to use the cout stream (for some inline logging code) and found this code to redirect cout to stdio:
#include "mbed.h"
#include <iostream>
class OutputBuffer : public std::streambuf {
public:
OutputBuffer() {
setp(0, 0);
}
virtual int_type overflow(int_type c = traits_type::eof()) {
return fputc(c, stdout) == EOF ? traits_type::eof() : c;
}
};
int main() {
printf("Hello world\n");
OutputBuffer ob;
streambuf *sb = cout.rdbuf(&ob);
cout << "Hello world again\n";
}
It works, which is great, however the compiler generates some warning messages:
"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/ostream"
"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/ostream"
"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/streambuf"
Are they indicative of a problem and could they be suppressed if not?
Thanks
Daniel
I would like to use the cout stream (for some inline logging code) and found this code to redirect cout to stdio:
It works, which is great, however the compiler generates some warning messages:
Are they indicative of a problem and could they be suppressed if not?
Thanks
Daniel