【发布时间】:2011-02-02 10:00:17
【问题描述】:
在 C++ 中将浮点类型的数据转换为整数有哪些不同的技术?
#include <iostream>
using namespace std;
struct database {
int id, age;
float salary;
};
int main() {
struct database employee;
employee.id = 1;
employee.age = 23;
employee.salary = 45678.90;
/*
How can i print this value as an integer
(with out changing the salary data type in the declaration part) ?
*/
cout << endl << employee.id << endl << employee.
age << endl << employee.salary << endl;
return 0;
}
【问题讨论】:
标签: c++ floating-point integer type-conversion typecast-operator