所以我花了最后几个小时试图谷歌并找出我的代码有什么问题,但我无法弄清楚。
我是一名学生,我刚刚开始学习线程等,所以这对我来说都是全新的,我不是很有经验。
谷歌(和这里)上的答案通常是对代码中一个特定问题的答案,我不知道如何真正让这件事起作用。
这是我的代码的一个非常简化的版本:
#include <iostream>
#include <string>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
struct Data{
string a;
string b;
};
void* thread_func( void *param ){
struct Data *input = (struct Data*)param;
string data1 = input->a;
string data2 = input->b;
cout << "You said: " << data1 << " " << data2 << endl;
return NULL;
}
int main( int argc, char *argv[] )
{
pthread_t child;
string arg, arg2;
struct Data *input;
cout << "Input …Run Code Online (Sandbox Code Playgroud)