2

Having troubles reading a file into a struct without eof. I have all of the needed includes in my .h file and I am getting an error that says "IntelliSense: no operator ">>" matches these operand"

struct Courses
{
    string mCourseID;
    double mCourseNumber;
    double mMaxCapacity;
    double mCurrentEnroled;
};

Courses addCourse(istream &File);


Courses addCourse(istream &File)
{
    Courses sData;

    File >> sData.mCourseID;
    File >> sData.mCourseNumber;
    File >> sData.mCurrentEnroled;
    File >> sData.mMaxCapacity;

    return sData;
 }

void readCourses(Courses sCourses[], ifstream &File, int &numCourses)
{
    while (addCourse(File) >> sCourses[numCourses])
    {

        numCourses++;
    }
}
3
  • 1
    Please post an MVCE Commented Feb 29, 2016 at 1:44
  • Is it OK to change addCourse()'s prototype? Commented Feb 29, 2016 at 1:47
  • man, this program is so academic, so many things could go wrong that they don't expect you to handle. Commented Feb 29, 2016 at 1:52

1 Answer 1

3

I think, you want to change the signature of addCourse to this...

istream& addCourse(istream &File, Courses& sData)
{
    File >> sData.mCourseID;
    File >> sData.mCourseNumber;
    File >> sData.mCurrentEnroled;
    File >> sData.mMaxCapacity;

    return File;
}

Then, modify your other function with these modifications...

void readCourses(Courses sCourses[], ifstream &File, int &numCourses)
{
    while (addCourse(File, sCourses[numCourses]))
    {
        numCourses++;
    }
 //......

But again, is your array sCourses big enough to hold as many Courses you will input? Or will you put a stopping condition? ...rethink your program logic.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked! Thanks so much! The limit will be ten courses, it should be fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.