Re: c++11, gcc 4.9.0: std::ostream o; gives protected errrors?
On Monday, March 31, 2014 7:34:41 PM UTC-7, Melzzzzz wrote:
On Mon, 31 Mar 2014 18:54:52 -0700 (PDT)
std::ostream o;
gives compile errors. says "protected" like all other iostreams in
gcc now in 4.9.0. Looked at the error. so I guessed:
std::ostream<char> o; this didn't work either.
well, I saw an example using a std::filebuf at
http://www.cplusplus.com/reference/ostream/ostream/ostream/ so, I
used the example code using streambuf. std::streambuf sbf;//this is
protected! agh!
http://www.cplusplus.com/reference/streambuf/basic_streambuf/basic_streambuf/
std::stringbuf sbf;//this is protected! agh!
http://www.cplusplus.com/reference/sstream/basic_stringbuf/
and filebuf is probably (?) unusable, since I am not dealing with a
file right now, I want it to work like std::cout for the time being.
f:\x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4\mingw64\x86_64-w64-mingw32\include\c++\streambuf:463:7:
error: 'std::ba sic_streambuf<_CharT, _Traits>::basic_streambuf()
[with _CharT = char; _Traits = std::char_traits<char>]' is protected
grep.cpp:21:16: error: within this context
compiling with c++ and using iostream has become impossible.
anyone with understanding on how to resolve this problem, please
do I have to start over from scratch and write my own compiler? ugh.
not something I can do. streams are getting harder and harder to use.
someone have a workaround?
just how am I supposed to use std::ostream now with c++11?
bmaxa@maxa:~/examples$ cat ostream.cpp
#include <ostream>
#include <iostream>
int main()
{
std::ostream o(std::cout.rdbuf());
o << "Hello World!\n";
}
bmaxa@maxa:~/examples$ g++-trunk -std=c++11 -Wall ostream.cpp -o ostream
bmaxa@maxa:~/examples$ ./ostream
Hello World!
bmaxa@maxa:~/examples$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/opt/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/opt/gcc-trunk CFLAGS='-O3 -march=native' CXXFLAGS='-O3 -march=native' --enable-languages=c,c++ --program-suffix=-trunk
Thread model: posix
gcc version 4.9.0 20140328 (experimental) (GCC)
--
Click OK to continue...
this works great. thanks. am working on unicode version.
so far, I have:
std::basic_streambuf<char16_t,std::char_traits<char16_t> > sbf;
std::basic_ostringstream<char16_t, std::char_traits<char16_t> > u16ograph(std::ios_base::out);
std::basic_ostream<char16_t, std::char_traits<char16_t> > u16cout(&sbf);
however, this is not working. I get
In file included from f:\x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4\mingw64\x86_64-w64-mingw32\include\c++\ios:43:0,
from f:\x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4\mingw64\x86_64-w64-mingw32\include\c++\ostream:38
,
from f:\x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4\mingw64\x86_64-w64-mingw32\include\c++\iostream:3
9,
from ostream2c.cpp:1:
f:\x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4\mingw64\x86_64-w64-mingw32\include\c++\streambuf:463:7: error: 'std::ba
sic_streambuf<_CharT, _Traits>::basic_streambuf() [with _CharT = char16_t; _Traits = std::char_traits<char16_t>]' is protected
basic_streambuf()
^
ostream2c.cpp:54:33: error: within this context
std::basic_streambuf<char16_t > sbf;
^
I am about at the end of my brain for now.