#include#include int main() { std::string line; std::ifstream myfile ("example.txt"); if (myfile.is_open()) { while ( std::getline (myfile,line) ) { std::cout << line << '\n'; } myfile.close(); } else std::cout << "Unable to open file"; return 0; }
#includeIn this example, getline reads input from the console until the user presses Enter. It then stores the input in the variable `name`, and prints a greeting message with the input. Package/Library: There are no external libraries used in this code example. This code uses the standard C++ libraries.#include int main () { std::string name; std::cout << "Please enter your name: "; std::getline (std::cin, name); std::cout << "Hello, " << name << "!\n"; return 0; }