2

I have the following code:

void Category:: fillCategories(char** & categories, char** &subset, std::ifstream *input, 
int*&subIndex)
{
    while(!input->eof())
    {
        char buffer[30];
        if (getCatSize()==getCatCapacty())
        {
            resize(categories, getCategoryCapAddress(), 5);
        }
        if (getSubSize()==getSubCap())
        {
            resize(subset, getSubsetCapAddress(), 5, subIndex);
        }
        std::getline(*input,buffer);
    }
}

for some reason

std::getline(*input,buffer); 

is giving me an error. Is there anything I can do to fix this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Anonymous
  • 93
  • 1
  • 6

1 Answers1

0

You should move getline up into the loop condition, and replace while with for, like this:

for (std::string buffer; getline(*input, buffer); )

And of course remove the char[] version of buffer. This way you have a dynamically sized buffer that works with std::getline and uses the correct termination condition.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436