填空题 以下程序设计功能是:将结构体变量time 中的内容写到文件中。 #include <iostream> using namespace std; struct date { int year; int month; int day; } int main ( ) { date time = { 2005, 1, 1 }; ofstream outdate; outdate.open( "d://date.txt", ios :: binary ); outdate.write(____________, sizeof( tt ) ); outdate.close(); return 0; } 则程序中空白处应该填入的语句为{{U}} 【15】 {{/U}}。
  • 1、
【正确答案】 1、(char*)&time    
【答案解析】[解析] 函数write的原型为: Ostream_type& write(const char *s,streamsize n); 其功能是输出s所指向的数据空间中的n个字符。函数返回对流对象本身的引用。 此函数要求流对象按模式ios_base::binary打开。