How do you read a line of text from a file in C++?

How do you read a line of text from a file in C++?
Answer
In C++, you may open a input stream on the file and use the std::getline() function from the <string> to read content line by line into a std::string and process them. std::ifstream file(“input. txt”); std::string str; while (std::getline(file, str)) { // process string … }
 

Tìm kiếm

Back
Top