Having trouble using get

I have to write a program that pulls data from a file. I cannot get the get function to work though. It keep s giving me an error. Here is my code so far:

#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>
using std::getline;
using std::cerr;
using std::string;
using std::fstream;
using std::ifstream;
using std::ofstream;

int main(){
string s;
ifstream inputPerson("person.dat");

if(!inputPerson){
cerr << "\nCannot locate file needed to be opened";
exit(1);
}
while(!inputPerson.eof()){
char a[1024];
s.get(a,1024, ",");
string t = a;
}
return 0;
}

and here is the error:
1>c:\users\chris\documents\visual studio 2008\projects\assignment 4\assignment 4\main.cpp(23) : error C2039: 'get' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]

Can someone help please this is frustrating
You can't get from a string...I think you are trying to use ifstreams .getline() instead.
while(!inputPerson.eof()){
char a[1024];
s.getline(a,1024, ",");
string t = a;
}
return 0;

like this because it gives me the same error?
I thought it had something to do with the string but I am not sure what to do to change it? The end result is that it will have a loop that takes in 2 strings and a int put it in a constructor, run it through some things and the output the new info into a new file. It will keep doing this until it reaches end of file
Anyone have any ideas?
closed account (S6k9GNh0)
It gives you getline is not a function?

http://cplusplus.com/reference/string/getline/

Read up. It's usually the only person with the correct answer.
You are calling s.getline() but std::string (you defined s as a string), does not have a member function called that or get(). I think you are trying to call your ifstreams .getline() (you defined it as inputPerson.
Don't use using std::ofstream; constructs.

Don't test a file stream eof(), rather, test the stream itself.

Use std::getline to read a line from a file.

Why dont use using std::ofstream?

and why do not test the eof()?
I didn't say don't use std::ofstream, I said, don't use using std::ofstream;. Really, you shouldn't use using at all, but if you must, pull in the entier namespace into the .cpp. Why? There are circumstances where it can get confusing, where the compiler isn't doing what you think.

The stream may reach the end, but it won't know it until a read is performed.
Interestingly enough I learned about the eof() yesterday when my file ran into an error because it had reached the end of file without knowing.

I also knew you said dont use using I just dont know how to encapsulate it in box so you might have missed where I put using std::ofstream. The reason I use using std::blah instead of just using using namespace::std is because my teacher requires we do it that way. he says that when you are using only a few functions from std then to to write each one: using std::blah
but he wants us to do that for all our assignments for grading purposes.
Use while (inputPerson) instead of while(!inputPerson.eof()).
will do thanks for the help
Topic archived. No new replies allowed.