一、单个C++程序(多线程)
//实现txt文件的读入并重写入另外一个txt文件中~ #include<fstream> //ifstream #include<iostream> #include<string> //包含getline() #include <string.h> #include <pthread.h> #include <windows.h> //#include<cmath> using namespace std; void* hjzgg(void* arg) { printf("hjzgg1\n"); while(1){ Sleep(900); printf("hjzgg\n"); //getchar(); } return NULL; } void* print_b(void* arg) { while(1){ Sleep(1000); cout<<"print_b"<<endl; //getchar(); } return NULL; } int main(int args, char* argv[]) { pthread_t temp; if(pthread_create(&temp, NULL, hjzgg, NULL) == -1) { printf("ERROR"); exit(1); } pthread_t tid; if(pthread_create(&temp, NULL, print_b, NULL) == -1) { printf("ERROR"); exit(1); } printf("**********main***111******\n"); while(1);//主线程不要提前结束 printf("**********main***222******\n"); return 0; }
二、新建项目(使用项目可添加多个.C和.H文件)
标签:多线程,void,DEV,C++,arg,include From: https://www.cnblogs.com/gengtongyu/p/17748596.html