C++捷径之三

来源:互联网 发布:淘宝联盟二合一口令 编辑:程序博客网 时间:2024/04/30 06:52

P108 4.9

 

struct inv_type{
 char item[40];
 double cost;
 double retail;
 int on_hand;
 int lead_time;
} invtry[SIZE];
  //使用数组结

 for(t=0; t<SIZE; t++)
  *invtry[t].item='/0';
 //初始化item数组

 

//系统时间
#include <iostream>
#include <ctime>
//时间库文件
using namespace std;

int main()
{
 struct tm *ptr;
//tm结构指针
 time_t lt;
//time_t类型

 lt=time('/0');//初始化
 ptr=localtime(&lt);

 cout<<ptr->tm_hour<<':'<<ptr->tm_min;
 cout<<':'<<ptr->tm_sec;
//

cout<<asctime(ptr);//
 cout<<endl;
 return 0;
}

 

//对于引用,函数的传递,还需更深的理解。

 

 

//按位显示U

void disp_binary(unsigned u)
{
 register int t;

 for(t=128; t>0; t=t/2)
  if( u&t)
   cout<<"1 ";
  else
   cout<<"0 ";

}

 

union{

  short int count;

  char ch[2];

 };

ch[0]='X';

ch[1]='Y';

cout<<count<<endl;// 匿名

 

//对类,在定义一个类的对象时,自动调用类的构造函数,在退出时,自动调用析构函数

 

//类的几种初始化方法。

class myclass{

 int a;

public:

 myclass(int x);

 int get_a();

};

myclass::myclass(int x)

{ a=x;    }

int myclass::get_a()

{ return a;    }

int main()

{

 myclass ob=4;//?????不是很明白

 myclass oc(444);

 myclass od=myclass(4444);//这个也不明白

 return 0;

}