Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <chrono>
- #include <ctime>
- class tmp {
- private:
- bool ativo;
- int n;
- void print_n() {
- while(true) {
- if(!ativo)
- return;
- std::clock_t start = std::clock();
- while(std::clock() - start < 1000) {
- if(!ativo)
- return;
- }
- std::cout << n << std::endl;
- //std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- }
- public:
- tmp() {
- ativo = true;
- }
- void setativo(bool set) {
- ativo = set;
- return;
- }
- void set(int v) {
- n = v;
- return;
- }
- void print() {
- //print_n(n);
- std::thread(&tmp::print_n, this).detach();
- return;
- }
- };
- tmp TMP;
- int main()
- {
- TMP.set(5);
- TMP.print();
- while(true) {
- int get;
- std::cin >> get;
- if(get == 0) {
- TMP.setativo(false);
- break;
- }
- TMP.set(get);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement