No matching function error.

Hi again all, having another issue with my program. Every time I try to read a value into an array which is a member of my structure I get a really odd error: no matching function for call to `std::basic_istream<char, std::char_traits<char> >::getline(std::string&, int)', starting at line 155 and then occurring every time I try to read a string into the array. I have the code attached. Any help would be greatly appreciated.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<sstream>
using namespace std; 

// Function prototypes

void enterCreatures(struct Creatures, struct Cost);
void printCreatures();
void printStatistics();
void saveCreaturesToFile();

struct Cost
{
   float numHours[50];
   double costPerHour[50];
   float foodCost[50];
   float supplyCost[50];
};

struct Creatures
{
   string name[50];
   string description[50];
   float avgLength[50];
   float avgHeight[50];
   string location[50];
   bool dangerous[50];
} Cost;



int main()
{
   
   bool goAgain = true; 
   
   int choice;
   
   cout << "Welcome to the Magical Creature Zoo Management Program!\n\n";
   
   while (goAgain == true)
   {
      cout << "What would you like to do?" << endl; 
      cout << "\t1. Enter some Magical Creatures." << endl; 
      cout << "\t2. List/Print Creatures." << endl; 
      cout << "\t3. Print Statistics on Creature Cost." << endl; 
      cout << "\t4. End Program." << endl; 
      cout << "\tEnter 1,2,3 or 4." << endl; 
      cout << "Choice: ";
      cin >> choice;
      cout << endl;
      
      if (choice == 1)
      {
         enterCreatures(Creatures, Cost);
      }
      
      else if (choice == 2)
      {
         printCreatures();
      }
      
      else if (choice == 3)
      {
         printStatistics();
      }
      
      else if (choice == 4)
      {
         saveCreaturesToFile();
         cout << "Thanks for using the Magical Creature Zoo Management Program!" << endl << endl;
         goAgain = false; 
      }
      
      else 
      {
         cout << "You did not enter a valid choice." << endl; 
         cout << "Please enter 1,2,3 or 4." << endl << endl; 
      }    
      
   }
          
system("PAUSE"); 

return 0;

}

// Function defenitions

void enterCreatures(struct Creatures, struct Cost)
{
   int choice;
   fstream file;
   char fileName[26];
   
   cout << "What do you want to do?" << endl;
   cout << "\t1. Load my creatures from a file." << endl; 
   cout << "\t2. Enter one creature manually." << endl;
   cout << "Choice: ";
   cin >> choice;
   cout << endl;
   
   if (choice == 1)
   {
      cin.ignore();
      cout << "What is the name of the file with your list of creatures? (ex: filename.txt)" << endl; 
      cout << "File name: "; 
      cin.getline(fileName,26);
      cout << endl << endl;
      
      file.open(fileName, ios::in);
      if(!file)
      {
         cout << fileName << " could not be opened." << endl << endl; 
      }
      
      else 
      {
         cout << "All creatures from " << fileName << " have been added to the program." << endl << endl;
      }
        
   }
   
   bool addAnother = true;
   Creatures creatureInfo;
   Cost a;
   int x =0;
   
   while (addAnother == true)
   {
   
   if (choice == 2)
   {
      cout << endl << endl;
      cin.ignore();
      cout << "Name: ";
      cin.getline(creatureInfo.name[x], 50);
      cout << endl << endl;
      cout << "Description: ";
      cin.getline(creatureInfo.description[x], 2500);
      cout << endl << endl;
      cout << "Average length (in feet): ";
      cin >> creatureInfo.avgLength[x];
      cout << endl << endl; 
      cout << "Average height (in feet): ";
      cin >> creatureInfo.avgHeight[x];
      cout << endl << endl; 
      cout << "Location: ";
      cin.ignore();
      cin.getline(creatureInfo.location[x], 50);
      cout << endl << endl; 
      cout << "Is it a dangerous creature? (y or n): ";
      cin >> creatureInfo.dangerous[x];
      cout << endl << endl; 
      cout << "How many hours do you spend caring for the " << creatureInfo.name[x] << " ?" << endl;
      cout << "Number of hours: ";
      cin >> a.numHours[x];
      cout << endl << endl;
      cout << "What is the cost per hour for caring for the " << creatureInfo.name[x] << " ?" << endl;
      cout << "Cost per hour: ";
      cin >> a.costPerHour[x];
      cout << endl << endl;
      cout << "How much money do you spend on food for the " << creatureInfo.name[x] << " ?" << endl;
      cout << "Food cost: ";
      cin >> a.foodCost[x];
      cout << endl << endl;
      cout << "How much money do you spend on grooming and medical supplies for the " << creatureInfo.name[x] << " ?" << endl;
      cout << "Supply Cost: ";
      cin >> a.supplyCost[x];
      
      
      
   }
   
   }
      
      
}

void printCreatures()
{
}

void printStatistics()
{
}

void saveCreaturesToFile()
{
}

float convertToFloat (string s)
{
  istringstream i(s);
  float x;
  if (!(i >> x))
     x = 0;
  
  return x;
}
      


Also, this is just my trial and error starting sort of code, am I even reading into the arrays defined in my structures correctly in the function titled "enterCreatures"?

Thanks again,

Zach
your compiler should point to an error at line 58, you're calling a function wrongly. it should be:
1
2
3
4
5
6
7
8
9
10
11
12
13
//define the struct/class
struct structName{/*struct members*/};

//function that accepts and process a struct declaration
void myFunc(structName);

//in main() or another function
structName st; //create an instance of your class/struct
myFunct(st); //pass an instance of the struct as parameter

//myFunc definition
void myFunc(structName sn)
{/*process the struct here*/}
Brilliant! Thanks a bunch matsom, it took a little tweaking but I've got it working for now. I'm sure I'll have some more questions but you guys here in the forum are awesome!! I appreciate all the help.
Topic archived. No new replies allowed.