To read a string input from the user in C++, you can use the std::getline function from the <string> header.
Here's an example code snippet:
#include <iostream>
#include <string>
int main() {
std::string name;
std::cout << "Enter your name: ";
std::getline(std::cin, name);
std::cout << "Hello, " << name << "!" << std::endl;
return 0;
}
In this example, std::getline reads the entire line of input, including any spaces, and stores it in the name variable.