News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ Tips: IO - string extraction

Started by ben2ong2, October 06, 2006, 11:19:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

(Newsgroups: comp.std.c++)


PROBLEM: You are not allowed to view links. Register or Login (M/K McSweeny)

Looking at the April 95 working paper, I cannot determine the expected
behaviour for code like:

[
   String x;

   for (int i = 0; i< ...; i++)
   {
      cin >> x;
      ...do something with x
   }
]

That is, does 'cin >> x' reset the string prior to reading it?  The
Plum-Hall libraries did reset the string, some newer environments are not.

Now assume that the words in the input stream are separated by two spaces
instead of one.  Should a null word be read between each pair of spaces or
should all leading whitespace be gobbled up prior to reading each word?


RESPONSE: You are not allowed to view links. Register or Login (Steve Clamage), 11 June 96

According to the latest working paper, the string extraction operator
appends characters to the string. No mention is made of resetting
the string, and indeed that would seem like peculiar behavior to me.

Initial whitespace skipping may be turned on or off. It is supposed
to be on by default. In that case, it doesn't matter how much
whitespace separates fields. All leading whitespace is skipped,
and data is read up to the next whitespace or until some other
termination condition is met.

If whitespace skipping is off, no whitespace will ever be read. Upon
encountering the first whitespace, no more input should occur by using
the string extractor. You would have to use unformatted input operations
to read or otherwise scan off the whitespace.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login