参数传递.cpp

来自「此代码是在多线程下」· C++ 代码 · 共 41 行

CPP
41
字号
// 参数传递.cpp : Defines the entry point for the console application.
//全局变量传递

#include "stdafx.h"
#include<iostream.h>
#include<process.h>
#include<windows.h>//不用此文件头则出错
//用全局变量传递数据
struct node{
	int data;
}*q;

DWORD WINAPI mythread(void *p)
{
	cout<<"the number is:"<<q->data<<endl;

    DWORD exitCode;
	ExitThread(exitCode);

	return 0;
}


int main(int argc, char* argv[])
{
	DWORD dw;
	HANDLE handle;
	q=(struct node *)malloc(sizeof(struct node));
	cout<<"Input number:";
	cin>>q->data;
	cout<<endl;
	Sleep(1000);

	handle=CreateThread(NULL,0,mythread,NULL,0,&dw);
	Sleep(1000);

	CloseHandle(handle);

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?