C++ Error
Oct 25 2007, 9:30 pm
By: l3lack-l3ahamut  

Oct 25 2007, 9:30 pm l3lack-l3ahamut Post #1



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.

Code
#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.

Oct 25 2007, 10:04 pm Kellimus Post #2



Quote from Vhaeraun
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.

Code
#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.

Oct 26 2007, 5:54 am l3lack-l3ahamut Post #3



Quote from Kellimus
Well, std::basic_ios&lt;_Elem,_Traits&gt;::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?

&lt;_Elem,_Traits&gt; 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.

Oct 26 2007, 8:33 am ShadowFlare Post #4



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.

Oct 26 2007, 8:32 pm Kellimus Post #5



Quote from ShadowFlare
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.

Oct 26 2007, 11:31 pm Esponeo Post #6



Input/Output streams must be passed by reference.

Also, your code sucks.



None.

Oct 26 2007, 11:36 pm Akar Post #7



Kellimus arguing with ShadowFlare? This'll be good. ShadowFlare pwnzorz in coding.



None.

Oct 30 2007, 6:44 pm Twitch Post #8



Quote from Akar
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.

Oct 30 2007, 11:10 pm Kellimus Post #9



Quote from Akar
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

Quote from Twitch
Quote from Akar
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.

Nov 9 2007, 12:10 am l3lack-l3ahamut Post #10



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?

Code
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



Code
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


Code
1>E:\School\CS121 Kuroski\Labs\lab08\Debug\lab08.exe : fatal error LNK1120: 2 unresolved externals




None.

Nov 9 2007, 1:32 am Esponeo Post #11



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.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[07:47 pm]
Ultraviolet -- Yeah, I suppose there's something to that
[2024-5-06. : 5:02 am]
Oh_Man -- whereas just "press X to get 50 health back" is pretty mindless
[2024-5-06. : 5:02 am]
Oh_Man -- because it adds anotherr level of player decision-making where u dont wanna walk too far away from the medic or u lose healing value
[2024-5-06. : 5:01 am]
Oh_Man -- initially I thought it was weird why is he still using the basic pre-EUD medic healing system, but it's actually genius
[2024-5-06. : 3:04 am]
Ultraviolet -- Vrael
Vrael shouted: I almost had a heart attack just thinking about calculating all the offsets it would take to do that kind of stuff
With the modern EUD editors, I don't think they're calculating nearly as many offsets as you might imagine. Still some fancy ass work that I'm sure took a ton of effort
[2024-5-06. : 12:51 am]
Oh_Man -- definitely EUD
[2024-5-05. : 9:35 pm]
Vrael -- I almost had a heart attack just thinking about calculating all the offsets it would take to do that kind of stuff
[2024-5-05. : 9:35 pm]
Vrael -- that is insane
[2024-5-05. : 9:35 pm]
Vrael -- damn is that all EUD effects?
[2024-5-04. : 10:53 pm]
Oh_Man -- https://youtu.be/MHOZptE-_-c are yall seeing this map? it's insane
Please log in to shout.


Members Online: jjf28, Roy