问题描述
- 关于操作系统的c++代码怎么会出现这样的错误?
-
#define _CRT_RAND_S
#include
#include "semaphore.h"
#include "thread.h"
#include
using namespace std;Semaphore mutex(1);
unsigned int WINAPI hello(void * param){
unsigned int time = 0;
while(TRUE){
rand_s(&time);
time %= 3000;mutex.P(); cout << GetCurrentThreadId() << " says hello .Sleep: "<< time << "ms"<<endl; mutex.V(); Sleep(time); } return 0;
}
#define THREAD_COUNT 3
int main(){
HANDLE hThread[THREAD_COUNT]; int i = 0; for( i = 0; i < THREAD_COUNT; i++){ hThread[i] = startThread(hello,NULL); } ::WaitForMultipleObjects(THREAD_COUNT,hThread,TRUE,INFINITE); for( i = 0; i < THREAD_COUNT; i++){ CloseHandle(hThread[i]); } return 0;
}
error C2065: 'rand_s' : undeclared identifier
error C2065: '_beginthreadex' : undeclared identifier
解决方案
定义的问题吧,好像是,未定义
解决方案二:
可能是软件兼容性的问题,不同系统的支持可能不一样,你找的看看
解决方案三:
rand_s _beginthreadex 这2个是你自己写的函数吗,是否包含头文件
时间: 2025-01-21 08:18:46