James Kanze
11/10/2008 8:41:00 AM
On Nov 9, 9:31 am, Terry IT <tryi...@gmail.com> wrote:
> On Nov 9, 11:33 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> > Terry IT wrote:
> > > On Nov 9, 9:19 am, red floyd <no.spam.h...@example.com> wrote:
> > >> Terry IT wrote:
> > >> > hi,
> > >> > i'm using code like this
> > >> > string s
> > >> > while(getline(cin,s)){
> > >> > process(s);
> > >> > }
> > >> > // this is the last line
> > >> > process(s);
> > >> This is wrong. s will not have new data after the loop.
> > > I thought if file contains no newline ,then s contains all
> > > the chars until the end of stream.
> > The point is not what s contains. The point is that you are
> > processing the last line twice. That is probably not what
> > you want.
> oh! That was a mistake. if i had to read a file line by line and
> output it how would i do it . if i get while(getline(cin,s)) cout
> <<s<<endl;
> outputs newline for everyline including the lastline. the
> lastline needn't have a newline but otherlines needs to be
> output with '\n'. How do i achieve it ?
I'm not sure what your motivation is. As I mentioned elsewhere,
it's implementation defined whether you can even write a text
file without a final newline; on most systems I've seen, you
can't. (Actually, Unix and Windows are probably about the only
ones where you can. And it doesn't have any real meaning, and
will cause all sorts of problems for other programs, under
Unix.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34