I am trying to get a cin running without interupting the cout (a dialogue for example or instructions).
If you do just cin >> a; while your cout(s) are running through it, it pauses the code to wait for user input, so I was directed to a new thread for it, as I am new and it's my first time using threads finally figuring it out I still have an issue, it waits for the main thread to finish before it completes the if statement (exit) but it will give the cout instantly.
Any help is appreciated.
#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(void)
{
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;
}