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.
[02:16 am]
Ultraviolet -- Suicidal Insanity
Suicidal Insanity shouted: http://photos.arlinghaus.org/Animals/Species/WesternJackdaw/2019.11.16-FSH_3770-QHD-%7BFA19D1D3-182C-4723-964D-C30A764A7D13%7D.jpg <- Its missing a speech bubble about SCR bad blizzard bad modding good 1.16 good
http://www.staredit.net/uploads/avatars/4811.png?312523688 pretty solid ;)
[02:14 am]
Ultraviolet -- That's supposed to be pr0nogo :P
[12:43 am]
MTiger156 -- Not sure why it takes an ultra-high resolution image of a bird to get that point across, but ok
[06:36 pm]
Suicidal Insanity -- fortheovermind
fortheovermind shouted: my turn rate bar from the Create panel is no longer there. my games are created with the default 12 and i can no longer modify it, what could be causing this?
Known patch bug
[06:07 pm]
Ultraviolet -- lifebot This version appears to be older than the version I already have downloaded (1.5). Why is this one being posted?
[06:03 pm]
Ultraviolet -- Zoan
Zoan shouted: MTiger156 lifebot woah, that's awesome! I'm too lazy right now to check, but does it work with Remastered or 1.1.16 only?
I haven't used it in the latest version of remastered, but I assume it still works. It definitely did before. It's pretty neat. Super fast & easy way to create a save/load system
[05:02 pm]
fortheovermind -- my turn rate bar from the Create panel is no longer there. my games are created with the default 12 and i can no longer modify it, what could be causing this?
[04:50 pm]
Zoan -- MTiger156
MTiger156 shouted: Also, here's a link to its actual description http://www.staredit.net/topic/17696/
lifebot woah, that's awesome! I'm too lazy right now to check, but does it work with Remastered or 1.1.16 only?
[04:18 pm]
Dem0n -- o nvm you're talking about SCDB, not the map
Please log in to shout.


Members Online: Roy, SonaBetancourt