Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Not sure what I am missing, but I am getting this error the namespace "std" has no member "getline"



Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0135	namespace "std" has no member "getline"	TDU attamp_t	C:\Users\Owner\source\repos\TDU attamp_t\TDU attamp_t\TDU attamp_t.cpp	32	


here is my code
----------------------------------------
#include <iostream>
#include <iterator> 
#include <map> 
#include "TDU attamp_t.h"
#include <algorithm>
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;
}



Thank you.

What I have tried:

I tried messing around with the header, #include <string>, but I'm so lost haha.
Posted
Updated 3-Mar-21 10:45am
v5
Comments
RedDk 2-Mar-21 16:31pm    
It's possible that "getline" (as is "std::getline") is not being recognized as getline is not defined in the namespace std. But if you go hunting through the include <string> (most likely> or <iostream> (less likely) ... you'll find that the proper way to access it is string::getline (likely) ... possibly std::string::getline. Notice that you've no reference to <string>. Now is it all coming back to you?
TangentJay 2-Mar-21 17:01pm    
Yes. I added #include <string> in the header, but that just gave me way more bugs haha. I'm working on a second one also and am still getting issues.
RedDk 2-Mar-21 17:11pm    
Well that can be expected. Eventually you'll get to a point where everything compiles and you've got an executable or a library. Then you can learn how to use the debugger when you find out that running it doesn't produce the results you expected :)

Also I'd recommend using other resoiurces as well. Like SO => https://stackoverflow.com/questions/50668814/vs2017-e0135-namespace-std-has-no-member-filesystem ... specifically the error above.

[edit]
... and don't repost you code.
[/edit]
k5054 2-Mar-21 17:51pm    
What's in #include "TDU attamp_t.h"? If I comment that out, remove using namepace std and properly specify cin, cout, pair, etc as being in namespace std, it compiles fine.
TangentJay 2-Mar-21 18:09pm    
Ok, thanks. Ill redo the code. I followed bits from youtube and been going on my own here and there.

I also checked out stackoverflow. bookmarked that and this site for later use. thanks again ill rework it.

1 solution

#include <iostream>
#include <iterator> 
#include <map> 


#include <string>

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;
}


This seems to work, though It is sloppy after I read some of your comments. Ill work on it .

But for some reason it won't run on my VS, but will run on the web.
 
Share this answer
 
Comments
Richard MacCutchan 3-Mar-21 4:45am    
The code works fine in Visual Studio insofar as it goes. But you do not check for the condition when an invalid TDU name is entered, or an invalid usage value is entered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900