Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to read a file line by line?

0 views
Skip to first unread message

jta...@hotmail.com

unread,
Oct 17, 2005, 12:09:27 PM10/17/05
to
Should i use the function getline?
the length of a line is unknown.
how to use it?
can someone show me a example?

jta...@hotmail.com

unread,
Oct 17, 2005, 12:09:39 PM10/17/05
to
Should i use the function getline?
the length of a line is unknown.
how to use it?
can someone show me an example?

jta...@hotmail.com

unread,
Oct 17, 2005, 12:09:36 PM10/17/05
to

mlimber

unread,
Oct 17, 2005, 12:16:33 PM10/17/05
to

Yes, use getline, but use it with a std::string:

#include <string>
#include <fstream>
using namespace std;

int main()
{
ifstream file( "file.txt" );
// Do error checking here

string str;
while( getline( file, str ) )
{
// ...
}
return 0;
}

Cheers! --M

pibru_...@tin.it

unread,
Oct 17, 2005, 2:55:16 PM10/17/05
to
does it work even if a line contains a space ?
>
> Cheers! --M
>

Kristo

unread,
Oct 17, 2005, 3:13:30 PM10/17/05
to
pi...@tin.it wrote:
> mlimber wrote:
> > jtan...@hotmail.com wrote:
> >
> >>Should i use the function getline?
> >>the length of a line is unknown.
> >>how to use it?
> >>can someone show me a example?
> >
> >
> > Yes, use getline, but use it with a std::string:

[snip code example]

> does it work even if a line contains a space ?

Yes. See here: http://www.cppreference.com/cppstring/getline.html

Kristo

jta...@hotmail.com

unread,
Oct 18, 2005, 2:15:37 AM10/18/05
to
When I compile this program, an error happened:
d:\c++work\gltest.cpp(20) : fatal error C1010: unexpected end of file
while looking for precompiled header directive

what does this error mean?
can some one give me help? Thank u!

John Harrison

unread,
Oct 18, 2005, 3:45:24 AM10/18/05
to

It means you told the compiler that you were using a precompiled header,
but then you didn't include one in your source file.

If you don't know what a precompiled header is then I would find the
right way to turn that feature off in your compiler. Compiler specific
questions are off topic here you should ask in a group appropriate to
your compiler if you can't figure out how to do this.

john

Jim Langston

unread,
Oct 19, 2005, 6:37:44 AM10/19/05
to
<jta...@hotmail.com> wrote in message
news:1129616137.3...@f14g2000cwb.googlegroups.com...

It means you are using a Microsoft compiler and have precompiled headers
turned on. I always turn them off myself. This is OS (compiler) even
specific but I'll answer for Microsoft Visual C++ .net 2003: Project -> ...
Properties -> C/C++ -> Precompiled Headers -> Create/Use Precompiled Header
Change that to Not Using Precompiled Header

0 new messages