Seekg - Example

Example

#include #include using namespace std; int main (int argc, char** argv) { // Open a new file for input/output operations discarding any current // content in the file (assumes a length of zero on opening) fstream myFile("test.txt", ios::in | ios::out | ios::trunc); // Add the characters "Hello World" to the file myFile << "Hello World"; // Seek to 6 characters from the beginning of the file myFile.seekg(6, ios::beg); // Read the next 5 characters from the file into a buffer char buffer; myFile.read(buffer, 5); // End the buffer with a null terminating character buffer = 0; // Output the contents read from the file and close it cout << buffer << endl; myFile.close; }

Read more about this topic:  Seekg

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)