Chinaunix首页 | 论坛 | 博客
  • 博客访问: 46242
  • 博文数量: 9
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-21 11:40
文章分类
文章存档

2008年(9)

我的朋友
最近访客

分类: C/C++

2008-05-30 17:22:43

#include
#include
#include
using namespace std;
 
int main()
{
        char *p[5];
        char s[64];
        int len = 5;
        int num = 0;
        struct timeval tv;
        struct timezone tz;
        for (int i = 0;i < len;++i)
        {
                p[i] = new char[64];
                stringstream ss;
                //取当前时间
                gettimeofday(&tv,&tz);
                cout << "秒:" << tv.tv_sec << ",微秒:" << tv.tv_usec << endl;
                srand(tv.tv_usec);
                num = rand();
                //类型转换
                ss << num;
                ss >> s;
                strcpy(p[i],s);
        }
        for (int i = 0;i < len;++i)
        {
                cout << "随机数" << i+1 << ":" << p[i] << endl;
                delete [] p[i];
        }
}
阅读(994) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~