Reading and Writing Files in C++ — a practical guide to C++ read write files with clear examples you can reuse in real projects.
C++ Tutorial Series (77/111). Prefer one article? Read the complete C++ tutorial.
Short description
Prefer RAII file streams over manual FILE* unless needed.
Read lines
#include <fstream>
#include <string>
std::ifstream in("data.txt");
std::string line;
while (std::getline(in, line)) {
std::cout << line << 'n';
}