Using Threads (Creating connecting etc)

I am trying to get cin on a different thread so that the cin will run without interfering with the cout stuff, but, this is my first time even thinking really of figuring out threads as i am still new (hints the beginner section) and so much is wrong with this but idk what
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <QCoreApplication>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <thread>
using namespace std;


string typesome;
thread releasecin;

int main()
{
    thread relc(releasecin, getline(cin, typesome);
    relc.join();
    cout << "Hey type something while i talk\n";
    cout << "I am a nice person\n";
    cout << "I like pie\n";
    cout << "At any time if i get out of line just type you good cuz to stop me\n";
    getline(cin, typesome);
    if (typesome == "you good cuz")
    cout << "You typed " << typesome << " I will stop";

    else
    continue;
    cout << "this is my story\n";


}

void releasecin()
{
    std::thread relc(releasecin, getline(cin, typesome));
};


Any help is appreciated
Last edited on
I've figured out the threads now and got the thread running yet the rest of the thread waits for the main to finish it self
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <QCoreApplication>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <thread>
#include <unistd.h>
#include <cstdlib>
using namespace std;


string typesome;
thread function1;

void function_1()
{
    //cout << "I am Running.. - CIN";
    getline(cin, typesome);
   //std::thread relc(releasecin, getline(cin, typesome));
    if (typesome == "you good cuz")
{
    cout << "You typed " << typesome << " I will stop\n";
    system("exit");
}
    else
{
    cout << "this is my story\n";
}

};

int main()
{

    std::thread t1(function_1); // Start the CIN
   // t1.join(); // Waits for the CIN to load
    cout << "Hey type something while i talk\n";
    usleep(10000000);
    cout << "I am a nice person\n";
    cout << "I like pie\n";
    usleep(10000000);
    cout << "At any time if i get out of line just type you good cuz to stop me\n";
    if (typesome == "you good cuz")
    cout << "You typed " << typesome << " I will stop";
    else
    cout << "this is my story\n";
    usleep(10000000);
    cout << "West philly born and raised\n";


    return 0;

}


It tells me the i typed thing and all that but waits to get to the west philly born and raised part before it exits, any help is appreciated
Topic archived. No new replies allowed.