本文整理汇总了C++中Number::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ Number::asString方法的具体用法?C++ Number::asString怎么用?C++ Number::asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Number
的用法示例。
在下文中一共展示了Number::asString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
std::string operator()(Number n) const {
return "#(" + n.asString() + ")";
}
示例2: test_number
void test_number() {
cout << "Testing class Number. ";
//cout << endl;
Number a = Number(1, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("1,0000000000"));
a += Number(2, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("3,0000000000"));
a += Number(-5, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("-2,0000000000"));
a += Number(2, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("-0,00000000000"));
a += Number(143, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("143,00000000"));
a -= Number(243, 32);
//cout << a.asString() << endl;
string b = a.asString();
//cout << b.length() << endl;
assert(a.asString() == string("-100,00000000"));
a /= Number(20, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("-5,0000000000"));
a *= Number(-3, 32);
//cout << a.asString() << endl;
assert(a.asString() == string("15,000000000"));
a -= Number(14, 32);
a >>= 4;
//cout << a.asString() << endl;
assert(a.asString() == string("0,062500000000"));
a <<= 4;
//cout << a.asString() << endl;
assert(a.asString() == string("1,0000000000"));
a >>= 32;
//cout << a.asString() << endl;
assert(a.asString() == string("0,00000000023283064365"));
a <<= 32;
//cout << a.asString() << endl;
assert(a.asString() == string("1,0000000000"));
Number f = Number(1, dec_to_bin(10));
f /= 3;
//cout << "%Rf: \"" << f.asFormatedString("%Rf") << '\"' << endl;
assert(f.asFormatedString("%Rf") == string("0.333333"));
//cout << "%*.Rf: \"" << f.asFormatedString(10) << '\"' << endl;
assert(f.asFormatedString(10) == string("0.333333333"));
//cout << "%*.*Rf: \"" << f.asFormatedString(
// "%*.*Rf", 12, 8) << '\"' << endl;
assert(f.asFormatedString("%*.*Rf", 12, 8) == string(" 0.33333333"));
f *= 3;
//cout << "%*.Rf: \"" << f.asFormatedString(10) << '\"' << endl;
assert(f.asFormatedString(10) == string("1.000000000"));
cout << "Ok." << endl;
}