首页 > 解决方案 > 需要一些输入才能运行此代码

问题描述

我在第 30 行不断收到错误消息。说

E0135   namespace "std" has no member "getline"

我将不胜感激任何反馈。我不确定我错过了什么。

#include <iostream>
#include <iterator> 
#include <map> 
using namespace std;
int main()
{
    //declaring variables
    string TDU;
    double usage;
    double total_charge;
    int run =1;
    //declare a map to store names of TDU and montly fixed costs in dollars
    map<string, double> monthlycharges; 
    monthlycharges.insert(pair<string, double>("ONCOR", 3.42)); 
    monthlycharges.insert(pair<string, double>("CENTERPOINT ENERGY", 5.47)); 
    monthlycharges.insert(pair<string, double>("AEP TEXAS CENTRAL", 9.00)); 
    monthlycharges.insert(pair<string, double>("AEP TEXAS NORTH", 10.53)); 
    monthlycharges.insert(pair<string, double>("TEXAS - NEW MEXICO POWER", 7.85)); 
    
    //declare a map to store names of TDU and usage costs in cents
    map<string, double> kwhcharges; 
    kwhcharges.insert(pair<string, double>("ONCOR", 3.8447)); 
    kwhcharges.insert(pair<string, double>("CENTERPOINT ENERGY", 4.03120)); 
    kwhcharges.insert(pair<string, double>("AEP TEXAS CENTRAL", 4.84460)); 
    kwhcharges.insert(pair<string, double>("AEP TEXAS NORTH", 4.01990)); 
    kwhcharges.insert(pair<string, double>("TEXAS - NEW MEXICO POWER", 4.83210)); 
   
    while(run==1){
    cout<<"Enter the name of TDU: "<<endl;
    std::getline(std::cin >> std::ws, TDU);
    cout<<"Enter the usage in kWh used: "<<endl;
    cin>> usage;
    //declare iterator of maps
    map<string, double>::iterator it_monthlycharges; 
    map<string, double>::iterator it_kwhcharges; 
    //use the find function of map to get the pointer to correct entry according to key 'TDU'
    it_monthlycharges = monthlycharges.find(TDU); 
    it_kwhcharges = kwhcharges.find(TDU); 
    //calculate the charges
    total_charge =it_monthlycharges->second + (it_kwhcharges->second*0.01*usage);
    //print the final output
    cout<<"TDU Delivery charges for "<<TDU<<" : "<<total_charge<<endl;
    cout<<"Enter 1 to calculate bill for another month, 0 to exit"<<endl;
    cin>>run;
    }
    return 0;
}

标签: c++

解决方案


推荐阅读