-
problem with structures
I have a problem when i use a structure in a function....
struct task
{
char task_descrip[50];
cont_info contractors;
material_info materials;
};
is invoked in :
void add_task(task& obj){
char ch;
cout<<"\n\n Please Enter the Following Information:";
for(int i=0; i<100; i++){
cout<<"\n\n Enter a brief task description: ";
cin.get(obj[i].task_descrip);
cin.ignore(100,'\n');
which is where i get an error, saying...
In function `void add_task(task &)':
: no match for `task &[int &]'
what am i doing wrong here?
Please help.....
-
how is add_task being called? From this statement:
>cin.get(obj[i].task_descrip);
it looks like obj is an array, but you dont declare it as such in your function definition:
>void add_task(task& obj)
you declare obj as a reference to task, not as an array. Maybe you meant
add_task(task *obj)
-
the argument to add_task() is a reference of type task called obj. As such obj will have a single example of each of the struct member variables, one of which is a char array called task_description. This char array can be viewed as a string. the best approach to place a string in this variable will be with getline() rather than get():
cin.getline(obj.task_descrip, 49);
which allows you to drop the char by char data entry associated with the loop. getline() allows inclusion of whitespace, such as spaces, in the string.
The call to ignore() is probably best used before the call to getline(), especially if you have used a call to >> at any time before the call to getline().