Basically this program is used to count the number of words in a file and also average the number of words per line. However I get this error:
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
Usually I can figure out what the hell its talking about but I'm not sure on this one.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
string getPath();
int wordsPerLine(ifstream inFile, int &lines);
int main()
{
int words,
lines,
avgPerLine;
string filePath;
ifstream inFile;
filePath = getPath();
inFile.open(filePath.c_str());
if (!inFile.is_open())
{
cerr << "Cannot open file: " << filePath << endl << endl;
exit (3);
}
words = wordsPerLine(inFile, lines);
avgPerLine = words / lines;
cout << "File Path: " << filePath
<< "\nNumber of words in file: " << words
<< "\nNumber of lines in file: " << lines
<< "\nAverage number of words per line: " << avgPerLine << endl;
return 0;
}
string getPath()
{
string path;
cout << "Enter full path of text file to be read: ";
cin >> path;
return path;
}
int wordsPerLine(ifstream inFile, int &lines)
{
int words = 0;
char ch;
lines = 0;
while (inFile.get(ch))
{
if (!(ch == (' ' || '\t' || '\n')))
{
words++;
inFile.ignore(100, (' ' || '\t' || '\n'));
}
else if (ch == '\n')
lines++;
}
return words;
}
None.
Basically this program is used to count the number of words in a file and also average the number of words per line. However I get this error:
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
Usually I can figure out what the hell its talking about but I'm not sure on this one.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
string getPath();
int wordsPerLine(ifstream inFile, int &lines);
int main()
{
int words,
lines,
avgPerLine;
string filePath;
ifstream inFile;
filePath = getPath();
inFile.open(filePath.c_str());
if (!inFile.is_open())
{
cerr << "Cannot open file: " << filePath << endl << endl;
exit (3);
}
words = wordsPerLine(inFile, lines);
avgPerLine = words / lines;
cout << "File Path: " << filePath
<< "\nNumber of words in file: " << words
<< "\nNumber of lines in file: " << lines
<< "\nAverage number of words per line: " << avgPerLine << endl;
return 0;
}
string getPath()
{
string path;
cout << "Enter full path of text file to be read: ";
cin >> path;
return path;
}
int wordsPerLine(ifstream inFile, int &lines)
{
int words = 0;
char ch;
lines = 0;
while (inFile.get(ch))
{
if (!(ch == (' ' || '\t' || '\n')))
{
words++;
inFile.ignore(100, (' ' || '\t' || '\n'));
}
else if (ch == '\n')
lines++;
}
return words;
}
Well, std::basic_ios<_Elem,_Traits>::basic_ios sounds like its a class within the Standard Namespace. It also seems like there is a "private" section of this class, and it can't access a function within there [/endstateobvious]
basic_ios sounds like Basic Input/Output Stream (Kind of like iostream.h), so it must have something to do with file access maybe?
<_Elem,_Traits> kind of sounds like a preset Global Variable (because in PHP, preset Global Variables are surrounded by _ _ s, like: __FILE__)...
Did you make that class? Cause if so, should there be a , after Elem? *Shrugs*
I'm not as advanced as you, so I don't know if I'm much help, except for ideas that I can provide... Maybe go through std namespace and check out the code?
None.
Well, std::basic_ios<_Elem,_Traits>::basic_ios sounds like its a class within the Standard Namespace. It also seems like there is a "private" section of this class, and it can't access a function within there [/endstateobvious]
basic_ios sounds like Basic Input/Output Stream (Kind of like iostream.h), so it must have something to do with file access maybe?
<_Elem,_Traits> kind of sounds like a preset Global Variable (because in PHP, preset Global Variables are surrounded by _ _ s, like: __FILE__)...
Did you make that class? Cause if so, should there be a , after Elem? *Shrugs*
I'm not as advanced as you, so I don't know if I'm much help, except for ideas that I can provide... Maybe go through std namespace and check out the code?
What I do know is that the linker or whatever it was adds the _ before stuff so that is probably why is says _Elem, _Traits
None.
You are trying to access a private member of the class; it is as simple as that. The compiler won't allow you to do that. You must be trying to access a part of the class that you aren't supposed to.
None.
You are trying to access a private member of the class; it is as simple as that. The compiler won't allow you to do that. You must be trying to access a part of the class that you aren't supposed to.
Hey, good job at stating the obvious
He wants to know how to fix it, not be told the obvious...
None.
Input/Output streams must be passed by reference.
Also, your code sucks.
None.
Kellimus arguing with ShadowFlare? This'll be good. ShadowFlare pwnzorz in coding.
None.
Kellimus arguing with ShadowFlare? This'll be good. ShadowFlare pwnzorz in coding.
Like I said soon he will run into a brick wall.In this case its gonna hurt big time
.
None.
Kellimus arguing with ShadowFlare? This'll be good. ShadowFlare pwnzorz in coding.
Wow, Akar. This post has set in stone, the mentality that you have.
Pointing out to someone that someone is asking for advice not for the obvious, isn't arguing with them.
If I was to argue with him, I'd say that he's wrong. All he did, was say what has already been pointed out.
Commenting != Arguing
Kellimus arguing with ShadowFlare? This'll be good. ShadowFlare pwnzorz in coding.
Like I said soon he will run into a brick wall.In this case its gonna hurt big time
.
Twitch, I think you've ran into too many already.
Commenting != Arguing
None.
I just had another question not related to this specific bit of code but I'm getting these errors while linking and I'm not really sure what it means by unresolved?
1>lab08.obj : error LNK2019: unresolved external symbol "void __cdecl writeFile(class std::basic_ofstream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,int * const,int * const,int * const,double * const)" (?writeFile@@YAXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@QAV32@2QAH33QAN@Z) referenced in function _main
1>lab08.obj : error LNK2019: unresolved external symbol "void __cdecl getData(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,int * const,int * const,class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?getData@@YAXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAV12@1QAH2AAV?$basic_ifstream@DU?$char_traits@D@std@@@2@@Z) referenced in function _main
1>E:\School\CS121 Kuroski\Labs\lab08\Debug\lab08.exe : fatal error LNK1120: 2 unresolved externals
None.
That means it doesn't know what the fuck writeFile is. Did you forget an include, a prototype, or maybe a scope resolution operator?
None.