home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16727 < prev    next >
Encoding:
Text File  |  1992-11-22  |  1.9 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!kithrup!hoptoad!pacbell.com!network.ucsd.edu!munnari.oz.au!metro!seagoon.newcastle.edu.au!mars!mazz
  3. From: mazz@mars (Richard Mazzaferri)
  4. Subject: Re: Can someone please help me with streams?
  5. Message-ID: <mazz.722443636@mars>
  6. Sender: news@seagoon.newcastle.edu.au
  7. Organization: Uni of Newcastle, Australia
  8. References: <1992Nov18.033505.1617@lugb.latrobe.edu.au> <75249@hydra.gatech.EDU>
  9. Date: Sun, 22 Nov 1992 14:47:16 GMT
  10. Lines: 33
  11.  
  12. andy@federation.gatech.edu (Andy Register) writes:
  13.  
  14. >In article <1992Nov18.033505.1617@lugb.latrobe.edu.au> ECSC9120802J@LUST.LATROBE.EDU.AU (GRANT,David) writes:
  15. >|>
  16. >|>I a new programmer to c++, and at the moment I am having trouble with streams.
  17. >|>I have overloaded the istream operator >>, to read in character by charater and
  18. >|>copy into an array. (It does a few other things as well.) The trouble I am
  19. >|>having is that I can't get it to recognise spaces or carrage returns. It just
  20. >|>seems to ignore them totally. I was wondering how I can get it to recognise
  21. >|>these characters, as it is inportant to my program. 
  22. >----------------------------------------------------------
  23. >Yep, istream ignores whitespace (blank, tab, newline, formfeed, cr).
  24.  
  25. >Try cin.get() instead.  Stroustrup, The C++ programming language, 2nd
  26. >ed., pp. 330-333 has examples.
  27.  
  28. Actually, this is only the default behaviour for istreams.  You can ask for
  29. white space not to be skipped by clearing the ios::skipws flag.  This
  30. can be achieved by 'cin.setf(0, ios::skipws)', and turned back on again
  31. via 'cin.setf(ios::skipws,ios::skipws)'.  Alternately you can use 
  32. manipulators to achieve the same effect in mid-input.
  33.  
  34.     char c;
  35.     cin >> resetiosflags(ios::skipws) >> c >> setiosflags(ios::skipws);
  36.  
  37.  
  38.    
  39.  
  40.     Mazz.
  41.  
  42. --
  43. Richard Mazzaferri        Ph.D. student          Uni. of Newcastle 
  44.   Ph (049) 216254   mazz@faceng.newcastle.edu.au     Australia.
  45.