mercredi 19 octobre 2016

How to make the program terminate when user types quit?

#include <thread>
#include <iostream>
using std::thread;
using std::this_thread::sleep_for;
using namespace std::chrono_literals;
using std::cout;
using std::cin;
using std::endl;

//input 
void inputThread(char* word)
{
    while (word != "quit")
    {   
        cin >> word;    
    }
}

void outputThread(char* word)
{
    while (word != "quit")
    {   
        cout << word << endl;
        cout << endl;
        sleep_for(1s);
    }
}
int main()
{
    char string[100] = { "Hello, Threads!" };
    thread input(inputThread, string);
    thread output(outputThread, string);

    input.join();
    output.join();

    return 0;
}

This simple program runs fine but doesn't terminate when i type quit. How can i make it so it quits when i type quit on the console?

It looks like your post is mostly code; please add some more details.

Aucun commentaire:

Enregistrer un commentaire