Re: c++ question regarding tellg()


Subject: Re: c++ question regarding tellg()
From: Avinash Gupta (agupta@mediaone.net)
Date: Wed Jan 09 2002 - 20:32:06 MST


Here is a modified sample that works for me:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
        string name("John");
        istringstream is(name);

        is.seekg(0);
        cout << "string buf = " << is.rdbuf() << endl;
        is.seekg(0);
        cout << "tellg() " << is.tellg() << endl;
        is.seekg(0);
        stringbuf *temp = is.rdbuf();
        cout << "length of buf = " << temp->in_avail() << endl;

        cout << endl;
        is.seekg(2);
        cout << "string buf = " << is.rdbuf() << endl;
        is.seekg(2);
        cout << "tellg() " << is.tellg() << endl;
        is.seekg(2);
        temp = is.rdbuf();
        cout << "length of buf = " << temp->in_avail() << endl;
        cout << name << endl;
        return 0;
}

and here is the output:

[agupta@laxmi agupta]$ g++ -o stream_test ./stream_test.cc

[agupta@laxmi agupta]$ ./stream_test
string buf = John
tellg() 268525696
length of buf = 4

string buf = hn
tellg() 268525698
length of buf = 2
John

-- Avinash Gupta (agupta@mediaone.net)

On Wednesday 09 January 2002 07:39, you wrote:
> Hi,
>
> I am wondering why the tellg() is only declared in iostream.h in the
> following rpms:
>
> gcc-2.95.4-4h
> gcc-c++-2.95.4-4h
> gcc-g77-2.95.4-4h
>
> Using gcc on an SGI, things appear to work but not on my ydl 2.1 version
> with the latest g++ compiler.
>
> Here is the sample code stream_test.cc
>
> #include <iostream>
> #include <sstream>
> #include <string>
>
> using namespace std;
>
> int main()
> {
> string name("John");
> istringstream instream(name);
> instream.seekg(1);
> cout << "tellg() " << instream.tellg() << endl;
> cout << "string buf = " << instream.rdbuf()->str() << endl;
> cout << "length of buf = " << instream.rdbuf()->str().size() <<
> endl; cout << name << endl;
> return 0;
> }
>
> compiling with: c++ -o stream_test stream_test.cc
>
> and running: ./stream_test results in the following:
>
> [jas@retriever jas]$ ./stream_test
> tellg() 268526225
> string buf =
> length of buf = 0
> John
>
> This is clearly not right. Am I missing some development rpms or is the
> g++ compiler for ppc not complete in this regard.
>
> Thanks,
>
> John Schmidt
> jas@netbrick.com



This archive was generated by hypermail 2a24 : Wed Jan 09 2002 - 20:45:46 MST