Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Seekg( ) moves the pointer offset number of characters from the specified origin

/* It must be one of these three values: ios::beg         Beginning-of-file ios::cur         Current location ios::end         End-of-file */ #include <iostream> #include <fstream> #include <cstdlib> using namespace std;     int main(int argc, char *argv[]) {   if(argc!=4) {     cout << "Usage: CHANGE <filename> <character> <char>\n";     return 1;   }       fstream out(argv[1], ios::in | ios::out | ios::binary);   if(!out) {     cout << "Cannot open file.";     return 1;   }       out.seekp(atoi(argv[2]), ios::beg);       out.put(*argv[3]);   out.close();       return 0; }