CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Posts
    11

    fstream : sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'

    Hi

    I am using fstream class for file I/O operations. When I upgrade my compiler to VC++ 7.1 from VC 6.0 I get compilation error on fstream related operation.
    With 6.0 I was using include fstream.h, while with VC++ 7.1 I am using fstream as fstream.h is no longer supported with 7.1.

    Sample Code:
    filebuf *pFb = Fb.open ("abc", ios:ut, filebuf::sh_write);

    Error:
    sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'


    Regards
    Devendra

  2. #2
    Join Date
    Jul 2005
    Location
    Russian Federation. Moscow
    Posts
    152

    Arrow Re: fstream : sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'

    MSDN said
    Code:
    basic_filebuf *open(
       const char *_Filename,
       ios_base::openmode _Mode
    );
    where the 3rd param?

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: fstream : sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'

    fstream is part of the STL library and is not the same as that used by fstream.h.

    What you probably need is...

    Code:
       filebuf *pFb = Fb.open("abc", ios_base::out);


    From MSDN...

    ios_base:penmode

    typedef T3 openmode; static const openmode app, ate, binary, in, out, trunc; The type is an enumerated type T3 that describes an object that can store the opening mode for several iostreams objects. The distinct flag values are:




    • app, to seek to the end of a stream before each insertion
    • ate, to seek to the end of a stream when its controlling object is first created
    • binary, to read a file as a binary stream, rather than as a text stream
    • in, to permit extraction from a stream
    • out, to permit insertion to a stream
    • trunc, to truncate an existing file when its controlling object is first created

  4. #4
    Join Date
    Jul 2003
    Posts
    11

    Re: fstream : sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'

    Thanks John.

    So with fstream the open function have 2 parameters only.

    But what is the alternate of sh_write/sh_read in fstream now ??

    Regards
    Devendra

  5. #5
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: fstream : sh_write is not a member of 'std::basic_filebuf<_Elem,_Traits>'

    Quote Originally Posted by devendraC
    But what is the alternate of sh_write/sh_read in fstream now ??
    To write to a file use an ofstream to read use an ifstream.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured