#include //C++ example #include #include using namespace std; int main(int argc, char **argv) { fstream fstr("file", ios_base::in | ios_base::out | ios_base::trunc); if (!fstr) { cerr << "can't open file.\n"; return EXIT_FAILURE; } fstr << "hello"; //Output five characters. cout << "input position == " << fstr.tellg() << "\n"; if (!fstr) { cerr << "can't tellg.\n"; return EXIT_FAILURE; } fstr.seekg(0); if (!fstr) { cerr << "can't seekg.\n"; return EXIT_FAILURE; } cout << "input position == " << fstr.tellg() << "\n"; if (!fstr) { cerr << "can't tellg.\n"; return EXIT_FAILURE; } char buffer[256]; //uninitialized variable fstr >> buffer; cout << buffer << "\n"; return EXIT_SUCCESS; }