The arguments are:

FILE* fp; // a file pointer
string line;

I am getting the following 3 error messages:

f:\X.cpp(214): error C2039: 'getline' : is not a member of
'std::basic_string<_Elem,_Traits,_Ax>'

with

[

_Elem=char,

_Traits=std::char_traits<char>,

_Ax=std::allocator<char>

]



f:\X.cpp(214): error C2784: 'std::basic_istream<_Elem,_Traits>
&std::getline(std::basic_istream<_Elem,_Traits>
&,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template
argument for 'std::basic_istream<_Elem,_Traits> &' from 'FILE *'



f:\X.cpp(214): error C2780: 'std::basic_istream<_Elem,_Traits>
&std::getline(std::basic_istream<_Elem,_Traits>
&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3
arguments - 2 provided



The only examples I saw anywhere are with the first argument being 'cin'.
Can't it be just any file pointer?

Anybody understand the error messages?



Thanks,

David

Re: A problem with the code: getline(fp,line); by thatsalok

thatsalok
Thu Feb 24 02:47:19 CST 2005


"David F" <David-White@earthlink.net> wrote in message
news:epsqONjGFHA.3092@tk2msftngp13.phx.gbl...
> The arguments are:
>
> FILE* fp; // a file pointer
> string line;
>
> I am getting the following 3 error messages:
>

Need Little bit of more coding snippet to Comment on your Problem.


--

With Regards
Alok Gupta
Visit me at http://alok.bizhat.com

"I think this will Help"



Re: A problem with the code: getline(fp,line); by Tom

Tom
Thu Feb 24 03:48:41 CST 2005

David F wrote:
> The arguments are:
>
> FILE* fp; // a file pointer

File pointers are part of C stdio, not C++ iostreams! std::getline is a
C++ stream IO function.

> string line;
>
> I am getting the following 3 error messages:
>
> f:\X.cpp(214): error C2039: 'getline' : is not a member of
> 'std::basic_string<_Elem,_Traits,_Ax>'
>
> with
>
> [
>
> _Elem=char,
>
> _Traits=std::char_traits<char>,
>
> _Ax=std::allocator<char>
>
> ]
>

That's perfectly true - string has no member called getline. I don't
know why you've got this error though - where have your written
"getline(fp,line)"?

>
> f:\X.cpp(214): error C2784: 'std::basic_istream<_Elem,_Traits>
> &std::getline(std::basic_istream<_Elem,_Traits>
> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template
> argument for 'std::basic_istream<_Elem,_Traits> &' from 'FILE *'

Right, getline doesn't take a FILE*, it takes a basic_istream. They are
completely different types, one part of the C IO library, one part of
the C++ IO library. The two don't mix very well.

> f:\X.cpp(214): error C2780: 'std::basic_istream<_Elem,_Traits>
> &std::getline(std::basic_istream<_Elem,_Traits>
> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3
> arguments - 2 provided
>
>
>
> The only examples I saw anywhere are with the first argument being 'cin'.
> Can't it be just any file pointer?

No! It can be any *stream*. If you want a particular file, use a
std::ifstream. e.g.
std::ifstream ifs("File.txt");
std::getline(ifs, line);

Tom

Re: A problem with the code: getline(fp,line); by David

David
Fri Feb 25 02:02:18 CST 2005

Many thanks. I was not aware that I have such a big hole in C++ - was not
aware on the scope
of the I/O streams classes which are unique to C++ (as oppose to C).

David

"Tom Widmer" <tom_usenet@hotmail.com> wrote in message
news:uvNZHYlGFHA.2616@tk2msftngp13.phx.gbl...
> David F wrote:
> > The arguments are:
> >
> > FILE* fp; // a file pointer
>
> File pointers are part of C stdio, not C++ iostreams! std::getline is a
> C++ stream IO function.
>
> > string line;
> >
> > I am getting the following 3 error messages:
> >
> > f:\X.cpp(214): error C2039: 'getline' : is not a member of
> > 'std::basic_string<_Elem,_Traits,_Ax>'
> >
> > with
> >
> > [
> >
> > _Elem=char,
> >
> > _Traits=std::char_traits<char>,
> >
> > _Ax=std::allocator<char>
> >
> > ]
> >
>
> That's perfectly true - string has no member called getline. I don't
> know why you've got this error though - where have your written
> "getline(fp,line)"?

This line was just in _tmain()
>
> >
> > f:\X.cpp(214): error C2784: 'std::basic_istream<_Elem,_Traits>
> > &std::getline(std::basic_istream<_Elem,_Traits>
> > &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce
template
> > argument for 'std::basic_istream<_Elem,_Traits> &' from 'FILE *'
>
> Right, getline doesn't take a FILE*, it takes a basic_istream. They are
> completely different types, one part of the C IO library, one part of
> the C++ IO library. The two don't mix very well.
>
> > f:\X.cpp(214): error C2780: 'std::basic_istream<_Elem,_Traits>
> > &std::getline(std::basic_istream<_Elem,_Traits>
> > &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3
> > arguments - 2 provided
> >
> >
> >
> > The only examples I saw anywhere are with the first argument being
'cin'.
> > Can't it be just any file pointer?
>
> No! It can be any *stream*. If you want a particular file, use a
> std::ifstream. e.g.
> std::ifstream ifs("File.txt");
> std::getline(ifs, line);
>
> Tom