-4

If I have:

String a;
cin >> a;
cout << a << endl;

What is the easiest way to have it read the full string including spaces.

  • Use std::getline. And read a good C++ text book. –  Apr 03 '17 at 23:54
  • What if "the full string" contains a line-break? What determines the length or delimiter of a string? – Dai Apr 03 '17 at 23:55
  • Could you show me in an example please. I don't know where to use that – radishapplepie Apr 03 '17 at 23:55
  • Well I just mean a full entry of a string, however long it needs to be – radishapplepie Apr 03 '17 at 23:56
  • std::string expands, limited only by system memory. What is your definition for "full string" (if not 0 or more characters terminated by a '\n')? Perhaps you are asking about binary files? Please clarify. – 2785528 Apr 04 '17 at 00:00
  • When does a string end? How does it know the user has stopped typing and will never type again? There must be some exit condition. When you are posed with a function with which you are unfamiliar, [one of the best places to look is cppreference](http://en.cppreference.com/w/). [Behind that is CPlusPlus.com](http://www.cplusplus.com/). cppreference aims for literal correctness (as you may have found, close ain't that useful in programming). CPlusPlus seems to try to get the explanations a bit more readable, and as a result is sometimes wrong. – user4581301 Apr 04 '17 at 00:15

1 Answers1

-1

This is actually basic c++ coding. I think this is what you're after. Also, there are quite a few good c++ books out there that are decent priced. Don't forget to #include

void newLine()
{
   char nextChar;
   do
   {
      cin.get(nextChar);
   } while (nextChar != '\n');
}