seek and fgets and fputs fopen

Discussion in 'C++' started by dave, Nov 1, 2006.

  1. dave

    dave Guest

    In c is it possible to open a file for read write and without using a buffer
    or second file change one character in the file and close it modified form

    ex.
    status.txt contains:
    This is mode 1.

    change to

    This is mode 3
    dave, Nov 1, 2006
    #1
    1. Advertising

  2. dave wrote:
    > In c is it possible to open a file for read write and without using a buffer
    > or second file change one character in the file and close it modified form


    see:

    std::eek:stream::seekp
    std::eek:stream::write
    Gianni Mariani, Nov 1, 2006
    #2
    1. Advertising

  3. dave

    BobR Guest

    dave wrote in message ...
    >In c is it possible to open a file for read write and without using a buffer
    >or second file change one character in the file and close it modified form
    >
    >ex.
    >status.txt contains:
    >This is mode 1.
    >
    >change to
    >
    >This is mode 3



    std::fstream Zstat("status.txt", std::ios::eek:ut | std::ios::binary);
    Zstat.seekp( 13 );
    if( not Zstat ){
    using std::cout; // for NG posting
    cout<<" file error="<<Zstat.flags()<<std::endl;
    cout<<" ios::good="<<Zstat.good()<<std::endl;
    cout<<" ios::bad="<<Zstat.bad()<<std::endl;
    cout<<" ios::eof="<<Zstat.eof()<<std::endl;
    cout<<" ios::fail="<<Zstat.fail()<<std::endl;
    }
    else{
    Zstat << "3";
    }

    --
    Bob R
    POVrookie
    BobR, Nov 2, 2006
    #3
  4. dave

    dave Guest

    "BobR" <> wrote in message
    news:NBb2h.166757$...
    >
    > dave wrote in message ...
    > >In c is it possible to open a file for read write and without using a

    buffer
    > >or second file change one character in the file and close it modified

    form
    > >
    > >ex.
    > >status.txt contains:
    > >This is mode 1.
    > >
    > >change to
    > >
    > >This is mode 3

    >
    >
    > std::fstream Zstat("status.txt", std::ios::eek:ut | std::ios::binary);
    > Zstat.seekp( 13 );
    > if( not Zstat ){
    > using std::cout; // for NG posting
    > cout<<" file error="<<Zstat.flags()<<std::endl;
    > cout<<" ios::good="<<Zstat.good()<<std::endl;
    > cout<<" ios::bad="<<Zstat.bad()<<std::endl;
    > cout<<" ios::eof="<<Zstat.eof()<<std::endl;
    > cout<<" ios::fail="<<Zstat.fail()<<std::endl;
    > }
    > else{
    > Zstat << "3";
    > }
    >
    > --
    > Bob R
    > POVrookie
    >
    >


    how bout using fopen with *FILE and fputs
    dave, Nov 2, 2006
    #4
  5. dave

    BobR Guest

    dave wrote in message ...
    >
    >how bout using fopen with *FILE and fputs


    Why, when you have std::fstream?

    std::ifstream Ping("Some.png", std::ios_base::binary );
    std::vector<unsigned char> Image;
    char In(0);
    while( Ping.get( In ) ){
    Image.push_back( static_cast<unsigned char>( In ) );
    }
    std::cout<<"\n Image.size() = "<<Image.size()<<" bytes."<<std::endl;

    --
    Bob R
    POVrookie
    BobR, Nov 2, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nonee
    Replies:
    2
    Views:
    2,638
    Neredbojias
    Oct 25, 2005
  2. Trying_Harder

    fgets,fopen, fclose

    Trying_Harder, Aug 26, 2003, in forum: C Programming
    Replies:
    5
    Views:
    672
    John Bode
    Sep 3, 2003
  3. fgets() and fopen() with "w"

    , Apr 1, 2008, in forum: C Programming
    Replies:
    2
    Views:
    314
  4. Michel Rouzic
    Replies:
    4
    Views:
    1,824
    Michel Rouzic
    Apr 28, 2008
  5. Replies:
    3
    Views:
    123
    Andreas Perstinger
    May 14, 2013
Loading...

Share This Page