cin.getline(): no matching function for call

carray is a pointer to the first car structure in an array of car structures, and num is an integer. I used cin.getline() in a for loop after I declared car. When I try to compile this, I get an error
saying, "error: no matching function for call to 'std::basic_istream<char>::getline(char[30])".


1
2
3
4
5
6
  struct car 
    {
        char make[30];
        int year;
    };
  cin.getline(carray[num].make);
closed account (j3Rz8vqX)
Edited: Yanson is correct; below.
I do not believe cin has a getline.

Use:
 
getline(cin,myStringVariable);


Make sure to include the <string> header.

http://www.cplusplus.com/reference/string/string/getline/
Last edited on
I do not believe cin has a getline.

http://www.cplusplus.com/reference/istream/istream/getline/?kw=cin.getline

[Edit]
cin.getline requires the size of the c_string
cin.getline(carray[num].make, 30);
Last edited on
closed account (j3Rz8vqX)
Ah, yes thank you Yanson.

Then the answer to OP is that cin.getline takes two arguments:

1) the c string

2) the maximum number of characters; capacity.

Possibly:
 
cin.getline(carray[num].make,30);


Which was posted in Yanson's link
Topic archived. No new replies allowed.