运营商>>结构过载?

时间:2012-07-11 01:43:15

标签: c++ overloading

  

可能重复:
  overload operator<< within a class in c++
  Operator overloading

这有可能吗?

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

据我所知,这是不可能的,但是我昨天参加了考试并且问了这个问题,它要求我写下缺失的函数。

2 个答案:

答案 0 :(得分:0)

在C ++中,结构与类相同。所以是的,你可以做同样的事情。

答案 1 :(得分:0)

添加include:

#include <stdlib.h>

您应该包含两个名称空间: 使用命名空间System; //即System :: Console 使用namespace std;

您需要使用:

std::cin >> t1.n;
相关问题