boost::shared_ptr<std::ofstream> don't write to file

Hello all im using boost::shared_ptr to init std::ofstream in it im declaring it as static : the .h file : typedef boost::shared_ptrstd::ofstream OFStreamPtrType; class Foo { static OFStreamPtrType iStream; } then in the cpp file : OFStreamPtrType Utilities::iStream(new ofstream("mylog.txt",ios::app)); Foo::printLog(string s){ if (Foo::iStream->is_open()) { Foo::iStream << c <<".\n"; } } no its opening the file mylog.txt but it is not writing any thing to it why ?

no its opening the file mylog.txt but it is not writing any thing to it> why ? probably, you test it before it flushes? try to flush() your stream, or disable buffering (oStream->rdbuf()->pubsetbuf(0, 0);)
Explore the seven wonders of the world http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE

AMDG Meir Yanovich wrote:
typedef boost::shared_ptrstd::ofstream OFStreamPtrType;
class Foo { static OFStreamPtrType iStream; }
then in the cpp file :
OFStreamPtrType Utilities::iStream(new ofstream("mylog.txt",ios::app)); Foo::printLog(string s){ if (Foo::iStream->is_open()) { Foo::iStream << c <<".\n"; } }
no its opening the file mylog.txt but it is not writing any thing to it why ?
It might help to dereference the pointer. *Foo::iStream << c <<".\n"; In Christ, Steven Watanabe

It might help to dereference the pointer.> > *Foo::iStream << c <<".\n";> > I thought he just misstyped it in this example. Is there the operator << (shared_ptr<...>, const string&) ?!
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

when im doing *Foo::iStream << c <<".\n";
im getting
error C2100: illegal indirection
On Wed, May 21, 2008 at 5:13 PM, Igor R.
It might help to dereference the pointer.
*Foo::iStream << c <<".\n";
I thought he just misstyped it in this example. Is there the operator << (shared_ptr<...>, const string&) ?!
________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it! _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 21 May 2008, at 15:28, Meir Yanovich wrote:
when im doing *Foo::iStream << c <<".\n"; im getting error C2100: illegal indirection
I think this code is roughly equivalent to what you're trying to do,
and it compiles with both g++ and icc. Test if you can compile this,
if so your problem is somewhere else.
#include

You probably didn't put here the *exact* code that you test.Anyway: apply << operator to the stream, not to the pointer or shared_ptr; ensure you flushed the stream.> > when im doing *Foo::iStream << c <<".\n";> im getting> error C2100: illegal indirection> _________________________________________________________________ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx

Thanks its working now
can you please explain me in short what is the benefits of boost::shared_ptr?
thanks
On Wed, May 21, 2008 at 5:46 PM, Igor R.
You probably didn't put here the *exact* code that you test. Anyway: apply << operator to the stream, not to the pointer or shared_ptr; ensure you flushed the stream.
when im doing *Foo::iStream << c <<".\n"; im getting error C2100: illegal indirection
________________________________ Get news, entertainment and everything you care about at Live.com. Check it out! _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Igor R.
-
Kevin Martin
-
Meir Yanovich
-
Steven Watanabe