structure error

Hi,
My structure looks like this:
1
2
3
4
5
6
struct stureg
{
    char fname [20];
    char lname [30];
    char stuid [10];
} stureg;


It works fine but when I change char stuid [20]; to int stuid [20]; I get error on compilation like this.
binary >> no operator found which takes a right-hand operand of type int [20]...
you get this error in structure or in main function?
post full code if its short with line no in error.

char stuid [20]; to int stuid [20]; ??
or

char stuid [10]; to int stuid [10]; ??
It probably works for char because char* is treated as a c string. If you want to use operator>> on all the elements in the array you can use a loop to do that.
C++ has an overload operator >> for class ifstream when the right operand is of type char * or char[]. However it has no overloaded operator >> for class ifstream when the right operand is an array of any other type. You should enter elements of an array of type int in a cycle. Something as

for ( int i = 0; i < 20; i++ ) std::cin >> stuid[i];

Or

int i = 20;

while ( i && std::cin >> stuid[--i] );
Last edited on
Topic archived. No new replies allowed.