Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > seek and fgets and fputs fopen

Reply
Thread Tools

seek and fgets and fputs fopen

 
 
dave
Guest
Posts: n/a
 
      11-01-2006
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


 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      11-01-2006
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:stream::seekp
std:stream::write
 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      11-02-2006

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: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


 
Reply With Quote
 
dave
Guest
Posts: n/a
 
      11-02-2006

"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: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


 
Reply With Quote
 
BobR
Guest
Posts: n/a
 
      11-02-2006

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
fopen() with full path affecting subsequent fopen calls Michel Rouzic C Programming 4 04-28-2008 04:48 PM
fgets() and fopen() with "w" vippstar@gmail.com C Programming 2 04-01-2008 10:48 PM
What is up with fopen??? FOpen and local directories Nonee HTML 2 10-25-2005 09:18 PM
fgets,fopen, fclose Trying_Harder C Programming 5 09-03-2003 05:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57