-2

writing a program for a class where we use functions to copy a list of data from an input txt file. One of my functions is to get the input for what file name they would like to search the data for. Heres my pre processor directions for my file as well as the function code, but on the .getline I keep getting the same error on my .getline line and i'm not sure how to fix this. Also was wondering if the general flow of my code makes sense. Thanks!

 #include <iostream>
 #include <iomanip>
 #include <string>
 #include <time.h>
 #include <stdlib.h>
 #include <fstream>
using namespace std;
const char PROGRAMMER[29] = "Matt Napoli & Jeff Koucoulis";
const char CLASS[5] = "CS1A";
const char SECTION[25] = "MW: Mon/Wed 5-7:20 PM";
const int LAB_NUM = 13;
const char LAB_NAME[17] = "Arrays in C++";
string input;
const int AR_SIZE = 10;




string checkFile()
{
    cout << "What input file would you like to use? ";
    cin.getline(cin, input);
    return input;
}

void filetoArray()
{
    cout << "Reading records from input file " << input;
    cout << "Who do you want to search for (enter done to exit)? " << endl;
    ifstream file(input);
        if(file.is_open())
        {
            string whatsInFile[AR_SIZE];

            for(int i = 0; i < AR_SIZE; ++i)
            {
                file >> whatsInFile[AR_SIZE];
            }
        }
}

As well here is my main.cpp file

 #include <iostream>
 #include <iomanip>
 #include <cstring>
 #include <string>
 #include <time.h>
 #include <stdlib.h>
 #include <fstream>
 using namespace std;
string input;
string inFile();
const int AR_SIZE = 10;
string whatsInFile[AR_SIZE];

int main() {
    int index = 0;
    void InFile();
    while (inFile && index < AR_SIZE)
    {
        void filetoArray();
    }
    return 0;
}

and my file with the input is here

Joe
Sally
Joe
Sue
Sally
Adam
Joe
Adam
Adam
Joe

1 Answers1

1

How about simple:

std::getline(cin, input);

instead of

cin.getline(cin, input);

which is wrong because signature of std::basic_istream<CharT,Traits>::getline is: basic_istream& getline( char_type* s, std::streamsize count );

RafalS
  • 3,464
  • 10
  • 20