i need opinion foer data structure im really stupid in this

using namespace std;

struct computer
char brand[20];
char serial_no[30];
int year_produce;

struct customer
char name[20];
char email[20];
computer favouriteComputer;

int main ()
cout<<"Enter name : ";
cout<<"Enter email : ";
cout<<favouriteComputer : " ;


return 0;
My opinion is that you're trying to inject C-style ways of doing things inside of a C++ program.

What happens when the brand, serial_no, name, or email entered is over 20 or 30 characters? There's no safety checks here, and no way to extend it. If this is just for a simple assignment, then it's fine. But if you're actually trying to write a robust program, it won't be acceptable.

Also, global variables like your adam variable are generally frowned upon. Declare adam in main instead.

But as far as actual errors, and not just opinions:

You'll also need a way to overload the >> operator to work with a computer object.

std::istream& operator>>(std::istream& is, computer& comp)
    return is >> comp.brand >> comp.serial_no >> comp.year_produce;

The compiler doesn't know what year_produce is by itself. You need to tell it you mean adam.favoriteComputer.year_produce. Same with the other variables.
Last edited on
1) Please use code tags when posting code, to make it readable:


2) The problem is that you're trying to use streaming operators << and >> to input and output your objects. However, the compiler can't magically know how to do that - you have to tell it how to do that.

Specifically, you have to override the << and >> operators to input and output whatever you want them to do.

If you don't know how to do this, search online for tutorials. Here's one I found from a simple Google search:

also tagging a variable on a class/struct is archaic and here it is also making a global with all those problems. just do

int main()
customer adam; //like a normal variable creation

customer has-a computer is fine.
Registered users can post here. Sign in or register to post.