-1

Kind of a convoluted question, but is it possible to read input from the user but making cin not stop at newlines or whitespaces? For example, the user can input:

Hello  w orld!


Hello World!

And I'd want all of the spaces and newline characters input into the string, just basically raw input from the user. Can someone tell me how I could do this in C++? Thanks.

  • You can choose another delimiter (end of input), then use `string o; std::getline(cin, o, '-');` ** WHERE "`-`" is the required delimiter, it is a SINGLE CHARACTER ** – user9335240 Feb 19 '18 at 05:11
  • Handy reading: https://stackoverflow.com/a/36978839/4581301 which makes [How to read until EOF from cin in C++](https://stackoverflow.com/questions/201992/how-to-read-until-eof-from-cin-in-c) a dupe of sorts. – user4581301 Feb 19 '18 at 05:44

1 Answers1

2

You could use std::getline for this as shown :

#include <iostream>
#include <string>

int main()
{
  std::string helloWorld;
  std::getline( std::cin, helloWorld );
  return 0;
}
Vishaal Shankar
  • 1,648
  • 14
  • 26