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. Advertisements

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. Alex Vinokur

    vector of ostringstream

    Alex Vinokur, Jul 10, 2003, in forum: C++
    Replies:
    4
    Views:
    1,023
    llewelly
    Jul 14, 2003
  2. Mark Warren
    Replies:
    3
    Views:
    16,955
    Sam Holden
    Jul 23, 2003
  3. Mike
    Replies:
    1
    Views:
    1,341
    John Harrison
    Aug 3, 2003
  4. James Madison

    ostringstream

    James Madison, Aug 5, 2003, in forum: C++
    Replies:
    2
    Views:
    573
    Grzegorz Sakrejda
    Aug 5, 2003
  5. Eric Boutin
    Replies:
    6
    Views:
    7,985
    Dan W.
    Dec 3, 2003
  6. jay
    Replies:
    4
    Views:
    3,508
  7. Replies:
    6
    Views:
    946
    Marcus Kwok
    Jan 10, 2006
  8. Mike Copeland

    ostringstream Question

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