#include #include #include #include #include #include using namespace std; void test_ptell() { cout << "Testing tellp." << endl; ostringstream ost1; ostrstream ost2; ofstream ofs("foobar"); FILE * fi = fopen("barfoo", "r"); cout << "ostringstream.tellp() = " << ost1.tellp() << "\n ostrstream.tellp() = " << ost2.tellp() << "\n ofstream.tellp() = " << ofs.tellp() << "\n ftell() = " << ftell(fi) << endl; } void test_pubseekoff_beg_out() { cout << "Testing pubseekoff(0, ios::beg, ios::out)" << endl; ostringstream ost1; ostrstream ost2; ofstream ofs("foobar"); FILE * fi = fopen("barfoo", "r"); cout << "ostringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::beg, ios::out) << "\n ostrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::beg, ios::out) << "\n ofstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::beg, ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_SET) << endl; } void test_pubseekoff_cur_out() { cout << "Testing pubseekoff(0, ios::cur, ios::out)" << endl; ostringstream ost1; ostrstream ost2; ofstream ofs("foobar"); FILE * fi = fopen("barfoo", "r"); cout << "ostringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::cur, ios::out) << "\n ostrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::cur, ios::out) << "\n ofstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::cur, ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_CUR) << endl; } void test_pubseekoff_end_out() { cout << "Testing pubseekoff(0, ios::end, ios::out)" << endl; ostringstream ost1; ostrstream ost2; ofstream ofs("foobar"); FILE * fi = fopen("barfoo", "r"); cout << "ostringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::end, ios::out) << "\n ostrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::end, ios::out) << "\n ofstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::end, ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_END) << endl; } void test_pubseekoff_beg_in() { cout << "Testing pubseekoff(0, ios::beg, ios::in)" << endl; istringstream ost1(""); istrstream ost2(""); ifstream ofs("foobar"); FILE * fi = fopen("barfoo", "w"); cout << "ostringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::beg, ios::in) << "\n ostrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::beg, ios::in) << "\n ofstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::beg, ios::in) << "\n fseek() = " << fseek(fi, 0, SEEK_SET) << endl; } void test_pubseekoff_cur_in() { cout << "Testing pubseekoff(0, ios::cur, ios::in)" << endl; istringstream ost1(""); istrstream ost2(""); ifstream ofs("foobar"); FILE * fi = fopen("barfoo", "w"); cout << "ostringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::cur, ios::in) << "\n ostrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::cur, ios::in) << "\n ofstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::cur, ios::in) << "\n fseek() = " << fseek(fi, 0, SEEK_CUR) << endl; } void test_pubseekoff_end_in() { cout << "Testing pubseekoff(0, ios::end, ios::in)" << endl; istringstream ost1(""); istrstream ost2(""); ifstream ofs("foobar"); FILE * fi = fopen("barfoo", "w"); cout << "istringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::end, ios::in) << "\n istrstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::end, ios::in) << "\n ifstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::end, ios::in) << "\n fseek() = " << fseek(fi, 0, SEEK_END) << endl; } void test_pubseekoff_beg_inout() { cout << "Testing pubseekoff(0, ios::beg, ios::in|ios::out)" << endl; stringstream ost1("", ios::in|ios::out); strstream ost2("", ios::in|ios::out); fstream ofs("foobar", ios::in|ios::out); FILE * fi = fopen("barfoo", "r+"); cout << "stringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::beg, ios::in|ios::out) << "\n strstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::beg, ios::in|ios::out) << "\n fstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::beg, ios::in|ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_SET) << endl; } void test_pubseekoff_cur_inout() { cout << "Testing pubseekoff(0, ios::cur, ios::in|ios::out)" << endl; stringstream ost1("", ios::in|ios::out); strstream ost2("", ios::in|ios::out); fstream ofs("foobar", ios::in|ios::out); FILE * fi = fopen("barfoo", "r+"); cout << "stringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::cur, ios::in|ios::out) << "\n strstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::cur, ios::in|ios::out) << "\n fstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::cur, ios::in|ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_CUR) << endl; } void test_pubseekoff_end_inout() { cout << "Testing pubseekoff(0, ios::end, ios::in|ios::out)" << endl; stringstream ost1("", ios::in|ios::out); strstream ost2("", ios::in|ios::out); fstream ofs("foobar", ios::in|ios::out); FILE * fi = fopen("barfoo", "r+"); cout << "stringstream.rdbuf()->pubseekoff() = " << ost1.rdbuf()->pubseekoff(0, ios::end, ios::in|ios::out) << "\n strstream.rdbuf()->pubseekoff() = " << ost2.rdbuf()->pubseekoff(0, ios::end, ios::in|ios::out) << "\n fstream.rdbuf()->pubseekoff() = " << ofs.rdbuf()->pubseekoff(0, ios::end, ios::in|ios::out) << "\n fseek() = " << fseek(fi, 0, SEEK_END) << endl; } int main() { test_ptell(); test_pubseekoff_beg_out(); test_pubseekoff_cur_out(); test_pubseekoff_end_out(); test_pubseekoff_beg_in(); test_pubseekoff_cur_in(); test_pubseekoff_end_in(); test_pubseekoff_beg_inout(); test_pubseekoff_cur_inout(); test_pubseekoff_end_inout(); }