VC雕虫小技集(一)[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 he_zhidan 的 blog

 

  vc雕虫小技集()

何志丹

1,避免随机数相同,可以取当前时间,读文件,读任意内存(如未定义变量,有一定危险).

       ctime t = ctime::getcurrenttime();

       int n = t.getminute() * 60 + t.getsecond();

       while(n-- > 0)

       {

              rand();

       }

       const int n = 100;

       int result = rand()%n;

 

 

2, 字符串与数的转换

sprintf,sscanf,其实还有其它许多函数,但只这两个函数是最容易记住的.因为它们和printf,scanf,fprint,fscanf的用法类似.

       char str[100];

       int    x = 5;

       sprintf(str,"%d",x);

       sscanf("10","%x",&x);

 

 

3,看一个键是否处于按下状态以及是否被按下过.

本文关键:vc 雕虫小技技
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top