代码之家  ›  专栏  ›  技术社区  ›  Tentacles

使用stod的getline()的和

  •  0
  • Tentacles  · 技术社区  · 9 年前

    int main()
    {
        // usual read file stuff
        while (!in.eof())                   
        {
    
            string total;
            double balance = stod(total);
            getline(in, total);
            cout << "$";
            cout << right << setw(10) << total << '.' << cout.precision(2) << endl;
            //guessing a for loop that would += balance
    }
    
    2 回复  |  直到 9 年前
        1
  •  2
  •   Danyal Imran    9 年前

    问题在于

    string total;
    double balance = stod(total);
    

    声明字符串后,您不知道 std::stod 就要回来了

    修复:

    string total;
    getline(in, total);
    double balance = stod(total);
    
        2
  •  1
  •   Ghulam Moinul Quadir    9 年前

    total double null 值和a 无效的 在为其分配字符串后加倍。只需阅读 全部的 使用前 stod()

    推荐文章