Need help with getline

So I am trying to take data from a file, and read it into my program using getline; however, when I try to compile I get this error message :

Person_Directory.cpp: In member function 'void Person_Directory::load_data(const std::string&)':
Person_Directory.cpp:28: error: invalid conversion from 'void*' to 'char**'
Person_Directory.cpp:28: error: invalid conversion from 'int' to 'size_t*'
/usr/include/stdio.h:581: error: too few arguments to function '__ssize_t getline(char**, size_t*, FILE*)'

this is the code where I am having difficulties.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Person_Directory.h"
#include "Student.h"
#include "Person.h"
#include "Salaried_Employee.h"
#include "Hourly_Employee.h"
#include <string>
#include <fstream>
#include <istream>
#include <ostream>
using namespace std;

void Person_Directory::load_data(const string& source_name){
	ifstream in(source_name.c_str());
	if(in) {
		int type;
		string name;
		string ssn;
		int age;
		string gender;
		double gpa;
		string major;
		int grad_year;
		string job_title;
		int hire_year;
		double hourly_rate;
		int hours_worked;
		int annual_salary;
		while(getline (in, type)) {
			Person* person;
			if(type == 1){
				getline (in, name);
				getline (in, ssn);
				getline (in, age);
				getline (in, gender);
				getline (in, gpa);
				getline (in, major);
				getline (in, grad_year);
				person* = new Student(name, snn, age, gender, gpa, major, grad_year));
				}else if(type == 2) {
					getline (in, name);
					getline (in, ssn);
					getline (in, age);
					getline (in, gender);
					getline (in, job_title);
					getline (in, hire_year);
					getline (in, hourly_rate);
					getline (in, hours_worked);
					person* = new Hourly_Employee(name, snn, age, gender, job_title, hire_year, hourly_rate, hours_worked);
					}else if( type == 3 ) {
						getline (in, name);
						getline (in, ssn);
						getline (in, age);
						getline (in, gender);
						getline (in, job_title);
						getline (in, hire_year);
						getline (in, annual_salary);
						person* = new Annual_Employee(name, snn, age, gender, job_title, hire_rear, hourly_rate, hours_worked);
					}
				directory.pushback(person);
				delete person;
			}
		}
	}
	


Not sure why this is happening since when I look at the c++ tutorial it does basically the same thing. I think that I am trying to use the std::getline and instead it is using istream's getline, is this the case? Any help would be greatly appreciated.
Last edited on
1
2
//line 28
... getline (in, type) ... //getline stores into a string right? (type is an int) 
Last edited on
Topic archived. No new replies allowed.