Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:05:47+00:00 2026-05-31T10:05:47+00:00

I’m trying to load lines of a text file containing dictionary words into an

  • 0

I’m trying to load lines of a text file containing dictionary words into an array object. I want an array to hold all the words that start with “a”, another one for “b” … for all the letters in the alphabet.

Here’s the class I wrote for the array object.

    #include <iostream>
    #include <string>
    #include <fstream>

    using namespace std;

    class ArrayObj
    {
    private:

        string *list;
        int size; 

    public:


        ~ArrayObj(){ delete list;}

        void loadArray(string fileName, string letter)
        {
            ifstream myFile;
            string str = "";
            myFile.open(fileName);

            size = 0;

            while(!myFile.eof())
            {
                myFile.getline(str, 100);

                if (str.at(0) == letter.at(0))
                    size++;
            }
            size -= 1; 

            list = new string[size];

            int i = 0;
            while(!myFile.eof())
            {
                myFile.getline(str, 100);

                if(str.at(0) == letter.at(0))
                {
                    list[i] = str;
                    i++;
                }
            }

            myFile.close();
        }


    };

I’m getting an error saying:

2   IntelliSense: no instance of overloaded function     "std::basic_ifstream<_Elem, _Traits>::getline [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list d:\champlain\spring 2012\algorithms and data structures\weeks 8-10\map2\arrayobj.h  39

I guess it’s requiring me to overload the getline function, but I’m not quite certain how to go about or why it’s necessary.

Any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:05:49+00:00Added an answer on May 31, 2026 at 10:05 am

    the function for streams that deals with std::string is not a member function of istream but rather a free function it is used like so. (the member function version deals with char*).

    std::string str;
    std::ifstream file("file.dat");
    std::getline(file, str);
    

    It is worth noting there are better safer ways to do what you are trying to do like so:

    #include <fstream>
    #include <string>
    #include <vector>
    
    //typedeffing is optional, I would give it a better name
    //like vector_str or something more descriptive than ArrayObj
    typedef std::vector<std::string> > ArrayObj
    
    ArrayObj load_array(const std::string file_name, char letter)
    {
        std::ifstream file(file_name);
        ArrayObj lines;
        std::string str;
    
        while(std::getline(file, str)){
            if(str.at(0)==letter){
                lines.push_back(str);
            }
        }
        return lines;
    }
    
    
    int main(){
        //loads lines from a file
        ArrayObj awords=load_array("file.dat", 'a');
        ArrayObj bwords=load_array("file.dat", 'b');
        //ao.at(0); //access elements
    }
    

    don’t reinvent the wheel; checkout vectors they are standard and will save you a lot of time and pain.

    Final try not to put in using namespace std that is bad for a whole host of reasons I wont go into; instead prefix std objects with std:: so like std::cout or std::string.

    http://en.cppreference.com/w/cpp/container/vector
    http://en.cppreference.com/w/cpp/string/basic_string/getline
    http://en.cppreference.com/w/cpp/string

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.