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


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

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


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

示例1: writeMoney

void writeMoney(ostream& out, long double val, bool intl = false) {

    // Create a writer facet
    const money_put<char>& moneyWriter =
            use_facet<money_put<char> >(out.getloc());

    // Write to the stream. Call failed() (the return value is an
    // ostreambuf_iterator) to see if anything went wrong.
    if (moneyWriter.put(out, intl, out, out.fill(), val).failed())
        throw "Couldn't write money!\n";
}
开发者ID:psychoss,项目名称:Everything,代码行数:11,代码来源:writing-and-reading-currency.cpp

示例2: translateDate

void translateDate(istream& in, ostream& out) {

   // Create a date reader
   const time_get<char>& dateReader =
     use_facet<time_get<char> >(in.getloc( ));

   // Create a state object, which the facets will use to tell
   // us if there was a problem.
   ios_base::iostate state = 0;

   // End marker
   istreambuf_iterator<char> end;

   tm t; // Time struct (from <ctime>)

   // Now that all that's out of the way, read in the date from
   // the input stream and put it in a time struct.
   dateReader.get_date(in, end, in, state, &t);

   // Now the date is in a tm struct. Print it to the out stream
   // using its locale. Make sure you only print out what you
   // know is valid in t.
   if (state == 0 || state == ios_base::eofbit) {
      // The read succeeded.
      const time_put<char>& dateWriter =
        use_facet<time_put<char> >(out.getloc( ));

      char fmt[] = "%x";

      if (dateWriter.put(out, out, out.fill( ),
                         &t, &fmt[0], &fmt[2]).failed( ))
         cerr << "Unable to write to output stream.\n";
   } else {
      cerr << "Unable to read cin!\n";
   }
}
开发者ID:jervisfm,项目名称:ExampleCode,代码行数:36,代码来源:13-4.cpp


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