1. double, float 类型小数点后取两位输出
1
2
|
printf ( "%0.2f\n" , number);
cout << fixed << setprecision(2) << number << endl; |
2. 无视空格输入一整行
1
2
3
4
5
|
string str; getline(cin, str); char
str[100];
gets (str);
|
3. 整数转化为字符串
1
2
3
4
5
6
7
8
9
|
char
str[100];
int n = 1000;
sprintf (str, "%d" , n);
#include <sstream> string result; int n = 10000;
stream << n; stream >> result; |
4. string 到 int 的转换
1
2
3
4
5
|
#include <sstream> string result = "100000" ;
int n = 0;
stream << result; stream >> n; |