I think it was the array that did it. After posting i tried
boy.name[index]
after realising i hadn't stated with element of the array to use, which
didn't work. I have just tried with
boy[index].name
and it works. i don't really understand most of what you said, but I looked
at the FAQ and it confuses me as it is very different from the book I am
learning basic c++ from (a complete idiots guide to c++ (Paul Snaith)) but
the array thing has fixed my problem. I will now attempt to use functions to
achieve this same outcome, then save the information in a binary file (no,
don't help me with this yet - i need to work it out). Also, emitting the
..h
from
iostream.h
returns an arror. I am using MSVC (v1.52).
Thanks for your help.
"Adam Fineman" <aBfLiOnDeDmYaVnI@KcIoNmGpSuter.org> wrote in message
news:GKP2b.196$Hi2.35392@news.uswest.net...[color=blue]
> Acacia wrote:[color=green]
> > i get this error on any line with dot notation. Oh, and do I need to use
> > cin.getline(boy.name)?:
> >
> > error:'.':left operand points to 'struct' use '->'
> >
> > This is the program in question:
> >
> > #include<iostream.h>[/color]
> #include <iostream> // no '.h' -- see the FAQ (link below)[color=green]
> > #include<string.h>[/color]
> // #include <string> or <cstring>... hard to tell which you need,
> // because you're not actually using either.
>
> using std::cout; // or, just 'using namespace std;
> using std::end;
> using std::cin;
>[color=green]
> >
> > #define MAX 20[/color]
> const unsigned int MAX = 20 // see the FAQ[color=green]
> > #define ARRAY 4[/color]
> const unsigned int ARRAY = 4;
>[color=green]
> >
> > struct monkey {
> > char name[MAX];[/color]
> // use std::string -- see the FAQ[color=green]
> > int age;
> > float weight;
> > };
> >
> > void main()
> > {
> >
> > struct monkey boy[ARRAY];[/color]
>
> You could use a std::vector here -- again, see the FAQ
>[color=green]
> > int index;
> >
> > for(index=0; index<ARRAY; index++)
> > {
> >
> > cout<<"MONKEY BOY "<<(index+1)<<" :"<<endl;
> > cout<<"Enter the name: ";
> > cin>>boy.name;[/color]
>
> // 'boy' is of type 'struct monkey []', which is an array.
> // You should have this instead:
>
> cin >> boy[index].name
>[color=green]
> > cout<<endl<<"Enter the age: ";
> > cin>>boy.age;
> > cout<<endl<<"Enter the weight: ";
> > cin>>boy.weight;
> > cout<<endl<<endl;
> >
> > }
> >
> > }
> >
> > Does anybody know what is wrong?
> >
> >[/color]
>
> You really need to read the FAQ:
http://parashift.com/c++-faq-lite/
>
> - Adam
>[/color]