std::oststream VS std::ostringstream

用如下程序段在for循环中分别测试std::oststream  和 std::ostringstream,可以发现std::oststream  有内存泄露,最好使用std::ostringstream。

  std::ostringstream oss, oss2;
   std::string strVal ; double var = 200.03234;
   //读入三位小数
   oss.setf(ios::fixed, ios::floatfield);
   oss.precision(3);
   oss << (double)var << '/0';
   
   double dblVal = 0;
   std::istringstream iss(oss.str());
   iss >> dblVal;
   
   //去掉尾数的0
   oss2<<std::setprecision(15)
    << dblVal << '/0';
   strVal = oss2.str().c_str();

posted on 2005-03-26 15:13  张大大123  阅读(138)  评论(0编辑  收藏  举报

导航