Why do I receive errors for using getline?

Hello,

Whilst running example code from a textbook, I receive errors from the compiler in relation to using getline(). I would like to extract the string from user input and use it within a data structure.

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
65
66
67
68
69
70
71

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int MAXRECS = 3; // maximum number of records

struct TeleType
{
	char name;
	char phoneNo;
	TeleType *nextaddr;
};

void populate(TeleType *); // function prototype needed by main()
void display(TeleType *); // function prototype needed by main()

int main()
{
	int i;
	TeleType *list, *current; // two pointers to structures of
							  // type TeleType
							  // get a pointer to the first structure in the list
	list = new TeleType;
	current = list;
	// populate the current structure and create the remaining
	// structures

	for (i = 0; i < MAXRECS - 1; i++)
	{
		populate(current);
		current->nextaddr = new TeleType;
		current = current->nextaddr;
	}

	populate(current); // populate the last structure
	current->nextaddr = NULL; // set the last address to a NULL address
	cout << "\nThe list consists of the following records:\n";
	display(list); // display the structures

	return 0;
}

// input a name and phone number
void populate(TeleType *record) // record is a pointer to a
{								// structure of type TeleType
	cout << "Enter a name: ";
	getline(cin, record->name);

	cout << "Enter the phone number: ";
	getline(cin, record->phoneNo);

	return;
}

void display(TeleType *contents)	// contents is a pointer to a
{									// structure of type TeleType
	while (contents != NULL)		// display until end of linked list
	{
		cout << endl << setiosflags(ios::left)
			<< setw(30) << contents->name
			<< setw(20) << contents->phoneNo;
		contents = contents->nextaddr;
	}
	cout << endl;
	
	return;
}


Example of one of the errors.
Severity Code Description Project File Line Suppression State
Error (active) E0304 no instance of overloaded function "getline" matches the argument list Example13.11 c:\Users\Kish\Documents\Visual Studio 2017\Projects\Example13.11\Example13.11\Example13.11.cpp 53
The code works if you change the type of name and phoneNo to std::string.
Registered users can post here. Sign in or register to post.