C++编程思想 第2卷 第4章 输入输出流 国际化 区域性字符流 输出法国流通货币符号和小数点分隔符

每个区域目录被分成几个领域
每个领域都是一些对应于相应目录封装了特定功能的类

目录monetary包含的领域有money_get money_put moneypunct

//: C04:Facets.cpp {-bor}{-g++}{-mwcc}{-edg}
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
#include <iostream>
#include <locale>
#include <string>
using namespace std;

int main() {
  // Change to French/France
  locale loc("french");
  cout.imbue(loc);
  string currency =
    use_facet<moneypunct<char> >(loc).curr_symbol();
  char point =
    use_facet<moneypunct<char> >(loc).decimal_point();
  cout << "I made " << currency << 12.34 << " today!"
       << endl;
  getchar();
} ///:~

可以定制自己的领域以构建个人化的区域
要当心,区域的开销可观


输出
I made €12,34 today!

猜你喜欢

转载自blog.csdn.net/eyetired/article/details/82055161