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
[snip code example]
> does it work even if a line contains a space ?
Yes. See here: http://www.cppreference.com/cppstring/getline.html
Kristo
what does this error mean?
can some one give me help? Thank u!
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
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