search

Home  >  Q&A  >  body text

java - C++ ostringstream问题

include <iostream>

include <sstream>

using namespace std;
int main()
{

ostringstream ostr("abcd");
ostr.put('1');
cout<<ostr.str();
cout<<endl;

ostr<<"hi";
ostr.put('56');  ///这边为何不是输出1bc56 而是1bc6?
cout<<ostr.str();

}

PHP中文网PHP中文网2802 days ago514

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:50:08

    ostringstream对象的put操作参数为charType. Reference

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:50:08

    Essentially equivalent to
    put((char)'56')

    reply
    0
  • Cancelreply