c++11, gcc 4.9.0: std::ostream o; gives protected errrors?

J

jmichae3

std::eek:stream 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::eek:stream<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::eek:stream now with c++11?
 
M

Melzzzzz

On Mon, 31 Mar 2014 18:54:52 -0700 (PDT)
std::eek:stream 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::eek:stream<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::eek:stream now with c++11?

bmaxa@maxa:~/examples$ cat ostream.cpp
#include <ostream>
#include <iostream>

int main()
{
std::eek:stream 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)
 
J

jmichae3

On Mon, 31 Mar 2014 18:54:52 -0700 (PDT)


std::eek:stream 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::eek:stream<char> o; this didn't work either.

well, I saw an example using a std::filebuf at
used the example code using streambuf. std::streambuf sbf;//this is
protected! agh!

std::stringbuf sbf;//this is protected! agh!


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.


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::eek:stream now with c++11?



bmaxa@maxa:~/examples$ cat ostream.cpp

#include <ostream>

#include <iostream>



int main()

{

std::eek:stream 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)

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::eek:ut);
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.
 
M

Melzzzzz

On Tue, 1 Apr 2014 12:26:06 -0700 (PDT)
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::eek:ut); 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.

You have to derive from basic_streambuf, I think. Not so easy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top