I changed cstring to string and I get the same error message. I found out how to copy the error messages so here is the code and all the messages that I get.
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
|
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
fstream file;
int i;
int lower_count = 0;
int upper_count = 0;
int alpha_count = 0;
int space_count = 0;
int punct_count = 0;
string filename;
cout << "Enter a file name" << endl;
cin >> filename;
file.open(filename, ios::in);
for (char c = file.get(filename); c !=EOF; c = file.get(filename))
{
if (isalpha(c))
{
alpha_count++;
}
else if (ispunct(c))
{
punct_count++;
}
else if (isspace(c))
{
space_count++;
}
else if ((file >= 'a' && file <= 'z'))
{
lower_count++;
i++;
}
else if ((file >= 'A' && file <= 'Z'))
{
upper_count++;
i++;
}
}
file.close();
cout << "-- File contents --" << endl;
cout << filename << endl;
cout << "-- End --" << endl;
cout << "File statistics:" << endl;
cout << "Uppercase characters: " << upper_count << endl;
cout << "Lowercase characters: " << lower_count << endl;
cout << "Punctuation characters: " << punct_count << endl;
cout << "Alphabetic characters: " << alpha_count << endl;
cout << "Whitespace characters: " << space_count << endl;
}
|
|21|error: no matching function for call to 'std::basic_fstream<char, std::char_traits<char> >::open(std::string&, const std::_Ios_Openmode&)'|
note: candidates are: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
|23|error: no matching function for call to 'std::basic_fstream<char, std::char_traits<char> >::get(std::string&)'|
note: candidates are: typename std::basic_istream<_CharT, _Traits>::int_type std::basic_istream<_CharT, _Traits>::get() [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT&) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]|
|23|error: no matching function for call to 'std::basic_fstream<char, std::char_traits<char> >::get(std::string&)'|
note: candidates are: typename std::basic_istream<_CharT, _Traits>::int_type std::basic_istream<_CharT, _Traits>::get() [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT&) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]|
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]|
||=== Build finished: 3 errors, 0 warnings ===|