2011-07-19 32 views
0

我使用srand的函數,在MS VS 2010如何使用時API使用C VS 2010下窗戶

srand((unsigned)time(NULL)); 

如下生成隨機值我已經拋出與以下錯誤。

error C3861: 'time': identifier not found 

我是否缺少這裏的任何東西?任何一個可以指出錯誤?

謝謝!

回答

0

#include <ctime>添加到程序文本的頂部(並且很好,並在說明時說std::time)。

0

包括time.h(時間),stdlib.h(用於函數srand),並使用::訪問全局範圍。

#include <time.h> 
#include <stdlib.h> 

void f() 
{ 
    ::srand((unsigned)::time(NULL)); 
} 
0

只是增加#include <time.h>應該解決的問題,如果使用C.

相關問題