如何在我的struct中使用库

时间:2018-03-22 09:40:24

标签: c++

struct date
{
  int day;
  int month;
  int year;
  void input()
  {
      std::cin>>day>>month>>year;
  }
};

#include<iostream>

main()
{
  date d1;
  d1.input();
}
除非包含iostream,否则

cin无效。但是我们不能将结构声明为全局,除非我们在main函数之前定义它。

如何在我的结构中使用库函数。

1 个答案:

答案 0 :(得分:5)

#include <iostream>置于顶部。这应该解决它。

通常包括在最开始时完成。这与代码块无关,只与c ++有关。