C/ C++ 输入输出流

1. double, float 类型小数点后取两位输出

printf("%0.2f
", number);
cout << fixed << setprecision(2) << number << endl;

  

2. 无视空格输入一整行

 

 string str;
 getline(cin, str);
 
 char str[100];
 gets(str);

  

3. 整数转化为字符串

 char str[100];
 int n = 1000;
 sprintf(str, "%d", n);
 
 #include <sstream>
 string result;
 int n  = 10000;
 stream << n;
 stream >> result;

  

4. string 到 int 的转换

 #include <sstream>
 string result = "100000";
 int n = 0;
 stream << result;
 stream >> n;

  

原文地址:https://www.cnblogs.com/zhouzhuo/p/3617981.html