Data File Handling & Classes

I've The Following Code:
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<string.h>
using namespace std;
class ab
{
public:
char name[10];
char reg[10];
char gend[10];
int age;
void set(char *a,char *b,char *c,int d)
{
strcpy(name,a);
strcpy(reg,b);
strcpy(gend,c);
age=d;
}
void putdata()
{
cout<<name<<endl;;
cout<<reg<<endl;
cout<<gend<<endl;
cout<<age<<endl;
}
};
int main()
{
ifstream f;
f.open("A1.txt",ios::in);
ab fin;
char ch,a[10],b[10],c[10];
int d;
if(!f) cout<<"\nCan't Open File!\n";
while(f.get(ch))
cout<<ch;
cout<<"\nAfter Reading:\n";
while(!f.eof())
{
getline(f,fin,',');
fin.set(a,b,c,d);
}
cout<<"\nNow Let's See If It's In Class:\n";
fin.putdata();
system("pause");
return 0;
}


I don't know why this is not working....
In the text file, say i've written:
Radon,12MCG245,Male,19
I just want to store this sort of information in class data members...pls help
I'm getting the following error:
c1.cpp|41|error: no matching function for call to 'getline(std::ifstream&, ab&, char)'
wht's wrong???
To use std::getline you must #include <string> and then the second parameter must be of type std::string, not ab.
Topic archived. No new replies allowed.