当前位置: 首页>>代码示例>>C++>>正文


C++ ostream::imbue方法代码示例

本文整理汇总了C++中std::ostream::imbue方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::imbue方法的具体用法?C++ ostream::imbue怎么用?C++ ostream::imbue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ostream的用法示例。


在下文中一共展示了ostream::imbue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: print

/** Prints out the column string at the given row index.
 *
 * @param s :: stream to output
 * @param index :: row index
 */
void PeakColumn::print(size_t index, std::ostream &s) const {
  Peak &peak = m_peaks[index];
  s.imbue(std::locale("C"));
  std::ios::fmtflags fflags(s.flags());
  if (m_name == "RunNumber")
    s << peak.getRunNumber();
  else if (m_name == "DetID")
    s << peak.getDetectorID();
  else if (m_name == "BankName")
    s << peak.getBankName();
  else if (m_name == "QLab")
    s << peak.getQLabFrame();
  else if (m_name == "QSample")
    s << peak.getQSampleFrame();
  else if (m_name == "h") {
    s << std::fixed << std::setprecision(m_hklPrec) << peak.getH();
  } else if (m_name == "k") {
    s << std::fixed << std::setprecision(m_hklPrec) << peak.getK();
  } else if (m_name == "l") {
    s << std::fixed << std::setprecision(m_hklPrec) << peak.getL();
  } else if (m_name == "PeakNumber") {
    s << peak.getPeakNumber();
  } else
    s << peak.getValueByColName(m_name);
  s.flags(fflags);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:31,代码来源:PeakColumn.cpp

示例2: float2string

void float2string(std::ostream& os, float value)
{
#ifdef SEXP_USE_CXX17
  constexpr size_t len = std::numeric_limits<float>::digits10 + 1;
  char buffer[len];
  auto result = std::to_chars(buffer, buffer + len, value);
  assert(result.ec == std::errc());
  os.write(buffer, result.ptr - buffer);
#else
  auto precision = os.precision(std::numeric_limits<float>::digits10 + 1);
#  ifdef SEXP_USE_LOCALE
  const auto& loc = os.getloc();
  os.imbue(std::locale::classic());
  os << value;
  os.imbue(loc);
#  else
  os << value;
#  endif
  os.precision(precision);
#endif
}
开发者ID:lispparser,项目名称:sexp-cpp,代码行数:21,代码来源:float.cpp

示例3: UTCTimeStamp

bool CConfigurationFile::CXML::save(std::ostream & os,
                                    const std::string & relativeTo)
{
  mPWD = relativeTo;

  os.imbue(std::locale::classic());
  os.precision(16);

  mpOstream = &os;

  *mpOstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
             << std::endl;

  *mpOstream << "<!-- generated with COPASI "
             << CVersion::VERSION.getVersion()
             << " (http://www.copasi.org) at "
             << UTCTimeStamp()
             << " UTC -->"
             << std::endl;

  saveParameter(mConfiguration);

  return true;
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:24,代码来源:CConfigurationFile.cpp

示例4: loc

// Save, change, and restore stream properties
void
saver_tests_1
(
    std::istream &  input,
    std::ostream &  output,
    std::ostream &  err
)
{
    using std::locale;
    using std::ios_base;
    using std::setw;

    boost::io::ios_flags_saver const      ifls( output );
    boost::io::ios_precision_saver const  iprs( output );
    boost::io::ios_width_saver const      iws( output );
    boost::io::ios_tie_saver const        its( input );
    boost::io::ios_rdbuf_saver const      irs( output );
    boost::io::ios_fill_saver const       ifis( output );
    boost::io::ios_locale_saver const     ils( output );
    boost::io::ios_iword_saver const      iis( output, my_index );
    boost::io::ios_pword_saver const      ipws( output, my_index );

    locale  loc( locale::classic(), new backward_bool_names );

    input.tie( &err );
    output.rdbuf( err.rdbuf() );
    output.iword( my_index ) = 69L;
    output.pword( my_index ) = &err;

    output << "The data is (again):\n";
    output.setf( ios_base::showpos | ios_base::boolalpha );
    output.setf( ios_base::internal, ios_base::adjustfield );
    output.fill( '@' );
    output.precision( 9 );
    output << '\t' << test_string << '\n';
    output << '\t' << setw( 10 ) << test_num1 << '\n';
    output << '\t' << setw( 15 ) << test_num2 << '\n';
    output.imbue( loc );
    output << '\t' << test_bool << '\n';

    BOOST_CHECK( &err == output.pword(my_index) );
    BOOST_CHECK( 69L == output.iword(my_index) );

    try
    {
        boost::io::ios_exception_saver const  ies( output );
        boost::io::ios_iostate_saver const    iis( output );

        output.exceptions( ios_base::eofbit );
        output.setstate( ios_base::eofbit );
        BOOST_ERROR( "previous line should have thrown" );
    }
    catch ( ios_base::failure &f )
    {
        err << "Got the expected I/O failure: \"" << f.what() << "\".\n";
        BOOST_CHECK( output.exceptions() == ios_base::goodbit );
    }
    catch ( ... )
    {
        err << "Got an unknown error when doing exception test!\n";
        throw;
    }
}
开发者ID:Albermg7,项目名称:boost,代码行数:64,代码来源:ios_state_test.cpp


注:本文中的std::ostream::imbue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。