Error in the program I can't find.

Recently I was developing a programming for just learning purpose. The program is about Nested Structure. I wanted to take it a little bit further so I included the 'Cin' function. I wanted the program to perform like if I enter a student's name, his details come up(like name, sex and age). Now the compiler is showing some error in the 'Cin' function which I totally can't figure out.
Please help :)

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
  #include <iostream>
#include <string>
using namespace std;
struct address{
    int house_no;
    string street_name;
};
struct student{
    string name;
    int rollno;
    address addr;
};
int main()
{
    student vishank; //my name
    vishank.name="vishank";
    vishank.rollno=1234;
    vishank.addr.house_no=68;
    vishank.addr.street_name="proctor road";
    student raj; //my friend's name
    raj.name="raj";
    raj.rollno=1222;
    raj.addr.house_no=70;
    raj.addr.street_name="v.p. road";
    cin>>student;
    cout<<"Enter student name to get the details"<<endl;
    if(student=vishank){
    cout<<vishank.name<<endl<<vishank.rollno<<endl<<vishank.addr.house_no<<endl<<vishank.addr.street_name;}
    else{
    cout<<raj.name<<endl<<raj.rollno<<endl<<raj.addr.house_no<<endl<<raj.addr.street_name;}
    return 0;
}
Namaste

check your line 25, you cant cin>>student the way you cant cin>>int, its a user (that's you) defined data type

hope it helps :)

PS: welcome to cplusplus.com
So what should I include?
Sth. like this - depending which student you want to input:
1
2
cin >> vishank.name;
cin >> vishank.addr.street_name;
Also cin>> is not a great choice use gets instead
Last edited on
Also cin>> is not a great choice use gets instead

What? The gets() function can never be use safely, never, Never, NEVER use this dangerous function. And remember that this dangerous C function only works with C-strings not C++ string.
What! I didn't knew that.... Thanks a lot jlb :)
Topic archived. No new replies allowed.