Nov 20, 2012 at 7:19pm UTC
I want to be able to input a text file and output the various results. However, I keep getting these two puzzling errors. I could really use some help on this one.
fourth.cc: In constructor âcountyElectionResults::countyElectionResults(std::string)â:
fourth.cc:38: error: cannot convert âstd::stringâ to âchar**â for argument â1â to â__ssize_t getline(char**, size_t*, FILE*)â
fourth.cc:40: error: no match for âoperator>>â in âcountyFile >> choicesâ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
#include<iomanip>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
class countyElectionResults{
friend ostream &operator <<(ostream &, countyElectionResults);
public :
countyElectionResults();
countyElectionResults(string);
bool loadFile(string);
string getCountyName();
vector<char > getVotes();
void showVotes();
int getNullifierVotes();
int getFielditeVotes();
int getOtherVotes();
int getTotalVotes();
private :
string countyName;
vector<char > votes;
int nullifierVotes;
int fielditeVotes;
int otherVotes;
int totalVotes;
void countVotes();
};
countyElectionResults::countyElectionResults(string countyFile) {
char choices = 'a' ;
getline(countyFile, countyName);
while (countyFile >> choices) {
switch (choices){
case 'N' :
case 'n' :
nullifierVotes++;
break ;
case 'F' :
case 'f' :
fielditeVotes++;
break ;
default :
otherVotes++;
break ; }
}
return ;
}
bool countyElectionResults::loadFile(string filename){
ifstream countyFile;
countyFile.open(filename.c_str());
if (!countyFile){
cout << "File not found. Please enter a valid file." << endl;
}
}
string countyElectionResults::getCountyName(){
return countyName;
}
int countyElectionResults::getNullifierVotes(){
return nullifierVotes;
}
int countyElectionResults::getFielditeVotes(){
return fielditeVotes;
}
int countyElectionResults::getOtherVotes(){
return otherVotes;
}
void countyElectionResults::countVotes() {
totalVotes = nullifierVotes + fielditeVotes + otherVotes;
}
int countyElectionResults::getTotalVotes() {
return totalVotes;
}
int main() {
countyElectionResults countyFile;
string filename;
cout << "Enter file name: " ;
cin >> filename;
cout << "Enter the county file to process: " ;
cin >> filename;
countyFile.loadFile(filename);
cout << setw(50) << countyFile.getCountyName() << endl;
cout << setw(30) << "Nullifier: " << setw(20) << countyFile.getNullifierVotes() << endl;
cout << setw(30) << "Fieldite: " << setw(20) << countyFile.getFielditeVotes() << endl;
cout << setw(30) << "Other: " << setw(20) << countyFile.getOtherVotes() << endl;
cout << setw(30) << "Total: " << setw(20) << countyFile.getTotalVotes() << endl;
cout << endl;
countyFile.showVotes();
cout << countyFile << endl;
return 0;
}
Last edited on Nov 20, 2012 at 7:20pm UTC
Nov 20, 2012 at 7:31pm UTC
What does the statement
getline(countyFile, countyName);
in the constructor
countyElectionResults::countyElectionResults(string countyFile)
mean?!!!
Before using any function please read its description.
Last edited on Nov 20, 2012 at 7:34pm UTC
Nov 20, 2012 at 7:40pm UTC
I am reading in the textfile called countyFile. The textfile is in this format:
COUNTY
n
f
f
n
s
n
s
So I am getting the county name from the county file wuth getline(countyFile, countyName)
Nov 20, 2012 at 8:00pm UTC
One more read the description of getline that to know what parameters it has.
string countyFile is obviously is not a stream of a file.
Last edited on Nov 20, 2012 at 8:00pm UTC
Nov 20, 2012 at 9:45pm UTC
1 2
@wootluke
I don't understand
Are you adequate?!!!
Read at last the description of the function before using it!
If you do not know how the function works then do not use it. Is this clear?!
Last edited on Nov 20, 2012 at 9:47pm UTC
Nov 20, 2012 at 10:27pm UTC
Way to be an asshole Vlad. I was simply seeking help. I wouldn't have posted my question if it could have been answered by me reading the function descriptions. It sometimes helps when someone explains it instead of berating me.
Nov 20, 2012 at 10:34pm UTC
And thanks CatFish2, got it now
Nov 20, 2012 at 10:41pm UTC
I'm glad that you've got it now. Just one comment. It helps us to help you if the questions are meaningful. Simply saying "I don't understand" is so brief and took so little effort to type, that it kind of implies that was the amount of effort you had made.
A longer question, emphasising where the explanation is required, helps people to apply their time and effort in a relevant way.
I know sometimes some of my own responses can be somewhat curt or abrupt, so I'd better say no more.