Program problems with getline()

while(!myfile.eof())
{getline(myfile,line_read);
if (name != line_read)
{
myfile << "\n";
myfile << name <<"\n";
}
}

Here is the code. My objective was to search through myfile, in a line by line manner and compare it to name. If it was not in the list, the program should add it to it.

Here is the error I get.

" error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ofstream'"


Thanks for any help provided. If more code is needed, please feel free to let me know and I will post it all.
Please provide a more complete example that demonstrates the problem.
You're trying to std::getline() from an output file stream. std::getline() needs an input stream as its first parameter.
Last edited on
Topic archived. No new replies allowed.