I get the error message request for member 'namn' in 'post', which is of non-class type 'telefonbok[10]', or similar versions of it.
I think it has to do with the following bit of code:
struct telefonbok
{
string namn;
string nummer;
};
int main()
{
int i, ja, nej;
telefonbok post[10];
What am I doing wrong?
The errors are targeted at:
cin>>post.namn;
and
cin>>post.nummer;
Here is the full code, sorry about the Swedish:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct telefonbok
{
string namn;
string nummer;
};
int main()
{
int i, ja, nej;
telefonbok post[10];
bool svar; //behövs för frågan om man vill fortsätta.
for (i=0; i<10; i++)
{
cout<<"Lagg till en post i telefonboken."<<endl;
cout<<"Ange personens namn"<<endl;
cin>>post.namn;
cout<<"Ange personens nummer :"<<endl;
cin>>post.nummer;
cout<<"Vill du mata in en post till? (ja/nej)"<<endl;
cin>>svar;
if (svar == nej) break; //stoppar slingan om man svarar nej
}
system("PAUSE");
return 0;
}
Thank you for any help that you may be able to provide.
postis an array, so accessing one member you need to docin>>post[index].namn;instead ofcin>>post.namn;You want to access a single
postelement in the array, and a member of that element.