I tried to use getline
but it give me some error
note: __ssize_t getline(char**, size_t*, FILE*)
My line is like this
ofstream myfile;
myfile.open("file.txt");
while(!myfile.eof())
{
getline(myfile,sline);
cout << sline;
}
How do i get my C++ to read file.txt
Ensure you have
#include <string>, wherestd::getline()is defined, and thatslineis astd::string.Change the structure of the loop to:
to avoid processing a failed read.
Use
std::ifstreamto read, notstd::ofstreamas pointed out by Karoly in the comments.