seek and fgets and fputs fopen

D

dave

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
 
G

Gianni Mariani

dave said:
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
 
B

BobR

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";
}
 
D

dave

BobR said:
dave wrote in message ...


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";
}

how bout using fopen with *FILE and fputs
 
B

BobR

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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top