Re: [CINT] [Fwd: [ROOT] string streams for g

From: Jiri Masik (masik@pc203b.fzu.cz)
Date: Sat Jan 19 2002 - 20:16:28 MET


Dear Masaharu,

thank you for your answer. I could not find a solution myself so I'm
sending more information to demostrate the problem

root [0] ostrstream buf; buf << 1 << ends;
root [1] buf.str()
(const basic_ostringstream<char,char_traits<char>,allocator<char>
>::__string_type)275332816

The return type of ostrstream.str() is different from how it works on
root compiled with gcc-2.95. It used to return char* which is
consistent with the docs at
http://darbujan.fzu.cz/cgi-bin/info2www?(iostream-295)Strings
Returning this type is what ostringstream should do I believe. 

Second try:
Including headers results in the following error
root [0] #include <string>
root [1] #include <strstream>
root [2] ostrstream buf; buf << 1 << ends;
root [3] buf.str()
Internal error: template function call G__ateval failed FILE: LINE:0
(const basic_ostringstream<char,char_traits<char>,allocator<char>
>::__string_type)276003640
*** Interpreter error recovered ***

I tried also the ostringstream class.
root [0] ostringstream o
root [1] o << "aaa"
(ostream)272904936
root [2] o.str()
(const basic_ostringstream<char,char_traits<char>,allocator<char>
>::__string_type)273024808

Then added just the string header. With the sstream header the same
internal error occurs on .str().

root [0] #include <string>
root [1] string a
root [2] ostringstream o  
root [3] o << "aaa"       
(ostream)273520856
root [4] a=o.str()
(string 0x0x10443110)"- .... 
and the session crashes. 

Do you have an idea what is wrong?
Thank you in advance for your response.

        Jiri


 

Masaharu Goto <MXJ02154@nifty.ne.jp> writes:

> Hello Jiri,
> 
> You need to include <string> in order to use << operator for string.
> 
> Thank you
> Masaharu Goto
> 
> 
> 
> 
> >Hi,
> >
> >I've been using stringstreams to compose object names within Root but
> >it doesn't work anymore on installations with gcc-3. For example
> >ostrstream.str() doesn't return char* as it should but basic_ostream...
> >
> >root [0] ostrstream buf; buf << 1 << ends; cout << buf.str() << endl;
> >Error: operator<< not defined for basic_ostream<char,char_traits<char> > 
> >FILE:/tmp/fileK3crvx_cint LINE:1
> >
> >I'd rewrite the code with ostringstream which should be more standard
> >but it suffers the same problem I can't copy stringstream contents
> >onto a string.
> >
> >Is there a way how to do it without moving to C-style string
> >management? I'm running 3.02-07 on linuxdeb2ppc/gcc-3.0.3. The same
> >version compiled with gcc-2.95 works fine.
> >
> >cheers
> >         Jiri
> >



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET