小编nul*_*dev的帖子

C++自动舍入

我下面的代码会自动舍入输入.我没有看到任何功能在任何地方围绕输入.有人可以看看吗?

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() 
 {
     string input = "";
     int weight = 0;
     int height = 0;
     int bmi = 0;
     while (true) 
     {
         cout << "Enter weight: ";
         getline(cin, input);
         // This code converts from string to number safely.
         stringstream myStream(input);
         if (myStream >> weight)
             break;
         cout << "Invalid number, please try again" << endl;
     }
     while (true) 
     {
         cout << "Enter height: " << endl;
         getline(cin, input);
         // This code …
Run Code Online (Sandbox Code Playgroud)

c++ rounding

2
推荐指数
1
解决办法
856
查看次数

标签 统计

c++ ×1

rounding ×1