1

Possible Duplicate:
overload operator<< within a class in c++
Operator overloading

Is there any way this is possible?

#include <iostream>
using namespace std;
struct test{
  int n;
};
int main(){
  test t1;
  cin >> t1;
  return 0;
}

For all I know, it is not possible, but I had an exam yesterday and that question came in it, it asked me to write the functions missing.

Community
  • 1
  • 1
hinafu
  • 689
  • 2
  • 5
  • 13

2 Answers2

0

In C++, structs are the same as classes. So yes, you can do the same thing as you do with classes.

Eric Finn
  • 8,629
  • 3
  • 33
  • 42
0

Add the include:

#include <stdlib.h>

You should include both namespaces: using namespace System; // ie System::Console using namespace std;

You'll need to use:

std::cin >> t1.n;
RetroCoder
  • 2,597
  • 10
  • 52
  • 81
  • 1
    a) The OP was supposed to write missing functions. It's very possible to overload `operator>>` to do that. b) `using namespace System;`? This is C++... Other than that, `` is preferred over `<*.h>`, and `using namespace std;` is a bit overrated. – chris Jul 11 '12 at 02:12