小编Web*_*er1的帖子

本书未能编译,将ifstream转换为bool的示例

我是C++的学生.我正在阅读"从C++早期对象开始(第9版)"一书.第6章(关于函数)的示例27从文件中读取数据但不会编译.以下是完整代码:

// Program 6-27
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

// Function prototype
bool readData(ifstream &someFile, string &city, double &rain);

int main()
{
    ifstream inputFile;
    string city;
    double inchesOfRain;

    // Display table headings
    cout << "July Rainfall Totals for Selected Cities \n\n";
    cout << " City      Inches \n";
    cout << "_________________ \n";

    // Open the data file
    inputFile.open("rainfall.dat");
    if (inputFile.fail())
    cout << "Error opening data file.\n";
    else
    {
        // Call the readData function
        // Execute …
Run Code Online (Sandbox Code Playgroud)

c++ intellisense visual-studio-2017

8
推荐指数
2
解决办法
395
查看次数

标签 统计

c++ ×1

intellisense ×1

visual-studio-2017 ×1