Yes, if you really insist. There's a version of getline
that's a member of std::istream
that will do it:
char buffer[1024];
std::ifstream myfile("text.txt");
while (myfile.getline(buffer, sizeof(buffer))
std::cout << buffer << "\n";
myfile.close();
Note, however, that most C++ programmers would consider this obsolescent at best. Oh, and for the record, the loop in your question isn't really correct either. Using string, you'd typically want something like:
std::string line;
std::ifstream myfile("text.txt");
while (std::getline(myfile, line))
std::cout << line << "\n";
myfile.close();
or, you could use the line
proxy from one of my previous answers, in which case it becomes simpler still:
std::copy(std::istream_iterator<line>(myfile),
std::istream_iterator<line>(),
std::ostream_iterator<std::string>(std::cout, "\n"));