Struct arrays

Idk if the title is correct but what I mean is that:
1
2
3
4
struct coords{
int x;
int y;
}a[1000];


My main question is why can't we use cin >> a[i] normally why does it have to be cin >> a[i].member of struct assuming this statement is under a loop ofc. is it because having a data of type "coords" for the array doesnt specify the kind of input to the values in it ? so we have to refer to the data type of the members of the struct since they are known data types? thanks in advance
>> is an operator. You can think of it as shorthand for a function.

In this case, the function is kind of like this:

getInputFromSomewhereAndPutItIntoSomething( placeToGetIt, placeToPutIt);

Did you write that function? No, you didn't. But C++ comes with a lot of these already written for you. A function for getting data from cin and putting it into an int. A function for getting data from cin and putting it into a string. A function for getting data from cin and putting it into a double. Here's a list of some:

http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/

Look at all the functions already written for you.

But there isn't one already written for you for taking data from cin and putting it into this struct you made. Why would there be?

Basically, as you said. Someone helpfully wrote some functions already for standard data types, but there's no way they could guess you were going to create some new data type like this. If you want that function, you've got to write it yourself.
Last edited on
Topic archived. No new replies allowed.