a question about ostringstream

Discussion in 'C++' started by Aman JIANG, Sep 18, 2007.

  1. Aman JIANG

    Aman JIANG Guest

    hello, i am a beginner to stringstream.

    int main()
    {
    ostringstream oss;
    for (int i = 0; i < 100; i++) {
    oss << "word " << endl;
    cout << oss.tellp() << " ";
    }
    }

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    why the result of ostringstream::tellp() is always zero ?

    but ofstream::tellp() works well:

    int main()
    {
    ofstream ofs("test.txt");
    for (int i = 0; i < 100; i++) {
    ofs << "word " << endl;
    cout << ofs.tellp() << " ";
    }
    }

    please 'tell' me why
    Aman JIANG, Sep 18, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov
    Replies:
    0
    Views:
    835
    Victor Bazarov
    Jun 25, 2003
  2. Russell Hanneken
    Replies:
    0
    Views:
    879
    Russell Hanneken
    Jun 25, 2003
  3. Alex Vinokur

    vector of ostringstream

    Alex Vinokur, Jul 10, 2003, in forum: C++
    Replies:
    4
    Views:
    673
    llewelly
    Jul 14, 2003
  4. Replies:
    6
    Views:
    816
    Marcus Kwok
    Jan 10, 2006
  5. Mike Copeland

    ostringstream Question

    Mike Copeland, May 1, 2013, in forum: C++
    Replies:
    2
    Views:
    174
    Bo Persson
    May 2, 2013
Loading...

Share This Page