c++ - 需要一些输入才能运行此代码
问题描述
我在第 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;
}
解决方案
推荐阅读
- r - 如何根据日期值对特定列重新排序?
- javascript - 需要一些帮助来理解 javascript 变量范围
- maven - 在 Maven 中,我可以将 Zip 存档中的 JEE 项目打包到 SQL 脚本中吗?
- excel - 为什么 Excel 在环绕 AND 时不会失败?
- ios - UITableView Swift 中的断言失败
- javascript - 是否可以使用 node.js 获取已安装的 Windows 更新列表?
- c++ - std::ifstream 和读取文件
- css - 物化预构建主题不适用
- api - Api Token Authentication - 通过参数或标头?
- php - 如何修复未捕获的 ArgumentCountError:函数 Update::index() 的参数太少,