From 90eb5438199f0fe2a1031316438febfe47d9c638 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 13 Nov 2019 20:22:25 +0300 Subject: [PATCH] Use std::cout instead of std::cerr in C++ example. GitOrigin-RevId: a61c925e7f432d5df46792ff6d4ccbcb3fda5b85 --- example/cpp/td_example.cpp | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/example/cpp/td_example.cpp b/example/cpp/td_example.cpp index b65c2761..befb2125 100644 --- a/example/cpp/td_example.cpp +++ b/example/cpp/td_example.cpp @@ -64,7 +64,7 @@ class TdExample { } else if (!are_authorized_) { process_response(client_->receive(10)); } else { - std::cerr << "Enter action [q] quit [u] check for updates and request results [c] show chats [m ] " + std::cout << "Enter action [q] quit [u] check for updates and request results [c] show chats [m ] " "send message [me] show self [l] logout: " << std::endl; std::string line; @@ -78,7 +78,7 @@ class TdExample { return; } if (action == "u") { - std::cerr << "Checking for updates..." << std::endl; + std::cout << "Checking for updates..." << std::endl; while (true) { auto response = client_->receive(0); if (response.object) { @@ -88,13 +88,13 @@ class TdExample { } } } else if (action == "close") { - std::cerr << "Closing..." << std::endl; + std::cout << "Closing..." << std::endl; send_query(td_api::make_object(), {}); } else if (action == "me") { send_query(td_api::make_object(), - [this](Object object) { std::cerr << to_string(object) << std::endl; }); + [this](Object object) { std::cout << to_string(object) << std::endl; }); } else if (action == "l") { - std::cerr << "Logging out..." << std::endl; + std::cout << "Logging out..." << std::endl; send_query(td_api::make_object(), {}); } else if (action == "m") { std::int64_t chat_id; @@ -103,7 +103,7 @@ class TdExample { std::string text; std::getline(ss, text); - std::cerr << "Sending message to chat " << chat_id << "..." << std::endl; + std::cout << "Sending message to chat " << chat_id << "..." << std::endl; auto send_message = td_api::make_object(); send_message->chat_id_ = chat_id; auto message_content = td_api::make_object(); @@ -113,7 +113,7 @@ class TdExample { send_query(std::move(send_message), {}); } else if (action == "c") { - std::cerr << "Loading chat list..." << std::endl; + std::cout << "Loading chat list..." << std::endl; send_query(td_api::make_object(nullptr, std::numeric_limits::max(), 0, 20), [this](Object object) { if (object->get_id() == td_api::error::ID) { @@ -121,7 +121,7 @@ class TdExample { } auto chats = td::move_tl_object_as(object); for (auto chat_id : chats->chat_ids_) { - std::cerr << "[id:" << chat_id << "] [title:" << chat_title_[chat_id] << "]" << std::endl; + std::cout << "[id:" << chat_id << "] [title:" << chat_title_[chat_id] << "]" << std::endl; } }); } @@ -162,7 +162,7 @@ class TdExample { if (!response.object) { return; } - //std::cerr << response.id << " " << to_string(response.object) << std::endl; + //std::cout << response.id << " " << to_string(response.object) << std::endl; if (response.id == 0) { return process_update(std::move(response.object)); } @@ -204,7 +204,7 @@ class TdExample { if (update_new_message.message_->content_->get_id() == td_api::messageText::ID) { text = static_cast(*update_new_message.message_->content_).text_->text_; } - std::cerr << "Got message: [chat_id:" << chat_id << "] [from:" << sender_user_name << "] [" + std::cout << "Got message: [chat_id:" << chat_id << "] [from:" << sender_user_name << "] [" << text << "]" << std::endl; }, [](auto &update) {})); @@ -225,20 +225,20 @@ class TdExample { overloaded( [this](td_api::authorizationStateReady &) { are_authorized_ = true; - std::cerr << "Got authorization" << std::endl; + std::cout << "Got authorization" << std::endl; }, [this](td_api::authorizationStateLoggingOut &) { are_authorized_ = false; - std::cerr << "Logging out" << std::endl; + std::cout << "Logging out" << std::endl; }, - [this](td_api::authorizationStateClosing &) { std::cerr << "Closing" << std::endl; }, + [this](td_api::authorizationStateClosing &) { std::cout << "Closing" << std::endl; }, [this](td_api::authorizationStateClosed &) { are_authorized_ = false; need_restart_ = true; - std::cerr << "Terminated" << std::endl; + std::cout << "Terminated" << std::endl; }, [this](td_api::authorizationStateWaitCode &) { - std::cerr << "Enter authentication code: "; + std::cout << "Enter authentication code: " << std::flush; std::string code; std::cin >> code; send_query(td_api::make_object(code), @@ -247,29 +247,29 @@ class TdExample { [this](td_api::authorizationStateWaitRegistration &) { std::string first_name; std::string last_name; - std::cerr << "Enter your first name: "; + std::cout << "Enter your first name: " << std::flush; std::cin >> first_name; - std::cerr << "Enter your last name: "; + std::cout << "Enter your last name: " << std::flush; std::cin >> last_name; send_query(td_api::make_object(first_name, last_name), create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitPassword &) { - std::cerr << "Enter authentication password: "; + std::cout << "Enter authentication password: " << std::flush; std::string password; std::cin >> password; send_query(td_api::make_object(password), create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitPhoneNumber &) { - std::cerr << "Enter phone number: "; + std::cout << "Enter phone number: " << std::flush; std::string phone_number; std::cin >> phone_number; send_query(td_api::make_object(phone_number, nullptr), create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitEncryptionKey &) { - std::cerr << "Enter encryption key or DESTROY: "; + std::cout << "Enter encryption key or DESTROY: " << std::flush; std::string key; std::getline(std::cin, key); if (key == "DESTROY") { @@ -299,7 +299,7 @@ class TdExample { void check_authentication_error(Object object) { if (object->get_id() == td_api::error::ID) { auto error = td::move_tl_object_as(object); - std::cerr << "Error: " << to_string(error); + std::cout << "Error: " << to_string(error) << std::flush; on_authorization_state_update(); } }