CPP 3. 处理数据 2020-10-13 浏览量 586 暂无评论 # 第3章 处理数据 ## 3.1 强制类型转换 ```cpp // typecast.cpp -- forcing type changes #include int main() { using namespace std; int auks, bats, coots; auks = 19.99 + 11.99; bats = (int) 19.99 + (int) 11.99; // old C syntax coots = int (19.99) + int (11.99); // new C++ syntax cout << "auks = " << auks << ", bats = " << bats; cout << ", coots = " << coots << endl; ``` ## 2 auto声明(C++11) 让编译器能够根据初始值的类型推断变量的类型。 并不是为初始化声明而生的(这根本没必要),反而会让人误入歧途,只有处理复杂类型,如标准模块库(STL)中的类型时,自动推断类型的优势才能显现出来,例如: ```cpp // C++98 std::vector scores; std::vector::iterator pv = scores.begin(); // C++11 std::vector scores; auto pv = scores.begin(); ``` 赞赏 微信支付 支付宝支付