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