I was assigned a program where the main calls a Word object and the Word object counts the vowels, consonants, digits, and special characters in the word. I've managed to do everything using cout, but when they ask me to use ofstream instead of ostream, I get errors that I don't know how to fix.
Here's a couple chunks of code from my main and my Word methods ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
int main(){
//initialization of everything
ostream writeout("output.txt");
//Word array filled out reading from input txt file
//Close input file
for(int i = 0; i < count; i++){
words[i].write(writeout);
writeout << endl;
}
writeout.close();
return 0;
}
void Word::write(ofstream &writeout) const{
writeout << setw(12) << left << words;
writeout << setw(8) << right << vowels;
writeout << setw(8) << right << consonants;
writeout << setw(8) << right << digits;
writeout << setw(8) << right << specialchars;
}
|
and I end up with the following errors:
Word.cpp:32: error: no match for 'operator<<' in 'writeout << std::setw(12) '
Word.cpp:33: error: no match for 'operator<<' in 'writeout << std::setw(8) '
Word.cpp:34: error: no match for 'operator<<' in 'writeout << std::setw(8) '
Word.cpp:35: error: no match for 'operator<<' in 'writeout << std::setw(8) '
Word.cpp:36: error: no match for 'operator<<' in 'writeout << std::setw(8) '
Any help would be greatly appreciated =)