#includeint main() { char buffer[256]; // Defines buffer size of 256 bytes std::cout << "Enter a string: "; std::cin.getline(buffer, 256); // Reads input from user and stores in buffer std::cout << "You entered: " << buffer << std::endl; return 0; }
#includeIn Example 1, the package library used is iostream because the standard input/output stream is used to read and write data to the console. In Example 2, the package library used is string because the string class is used to create a dynamic buffer size and store the input.#include int main() { std::string buffer; // Defines dynamic buffer size std::cout << "Enter a string: "; std::getline(std::cin, buffer); // Reads input from user and stores in buffer std::cout << "You entered: " << buffer << std::endl; return 0; }