I have to read a whole line from the console and store it into a std::string
and a char
array,
e.g.
"Hi this is balaji"
Now I have to read the above string and store it into string
. I tried it using the getline()
function.
Try:
#include <string>
#include <iostream>
int main()
{
std::string line;
std::getline(std::cin, line); // read a line from std::cin into line
std::cout << "Your Line Was (" << line << ")\n";
std::getline(std::cin, line); // Waits for the user to hit enter before closing the program
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With