#include#include int main() { std::ifstream inputFile("filename.txt"); char c; // Read a single character from the file inputFile.get(c); std::cout << "Read character: " << c << std::endl; return 0; }
#includeIn this example, we open a file named `filename.txt` and read a line of text from it using the `getline` function. The line of text is then printed to the console. The `ifstream` class is part of the standard C++ library, which is included with most C++ compilers. No additional package or library is required.#include int main() { std::ifstream inputFile("filename.txt"); std::string s; // Read a string from the file std::getline(inputFile, s); std::cout << "Read string: " << s << std::endl; return 0; }