我希望有人可以提供一些有关特定问题的见解。我正在编写一个程序,它采用整数,将它们存储在一个向量中,并用逗号分隔符将它们打印出来,数字大于999 - > 1,000。重载<<并定义一个流操作器C++
我的问题是..好吧,其实两个,我怎样才能传递一个矢量到一个函数,第二,如果我想超载的所有这些在幕后将是可能的吗?
从类逗号全局函数:
template <class T>
string formatWithComma(T value){
stringstream ss;
locale commaLoc(locale(), new CommaNumPunc());
ss.imbue(commaLoc);
ss << value;
return ss.str();
环在main()显示矢量:
for (vector<unsigned int>::iterator i = integers.begin(); i != integers.end(); ++i){
cout << formatWithComma(*i) << " ";
}
你不需要编写自定义'locale'有逗号分隔的数字,' num_punct'应该用','作为分隔符,'3'作为数字分组 – 2013-05-05 23:28:21