diff --git a/.vscode/settings.json b/.vscode/settings.json index ac0711c..2b3ea78 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -107,6 +107,26 @@ "span": "cpp", "valarray": "cpp", "variant": "cpp", - "xstring": "cpp" + "xstring": "cpp", + "chrono": "cpp", + "filesystem": "cpp", + "ios": "cpp", + "locale": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/handle.cpp b/handle.cpp index 8ab59c8..8c587ba 100644 --- a/handle.cpp +++ b/handle.cpp @@ -4,6 +4,7 @@ #include #include #include +#include CHttpsHandle::CHttpsHandle() { diff --git a/main.cpp b/main.cpp index 70d8626..9886310 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,9 @@ #include #include #include -#include #include +#include +#include // #include using json = nlohmann::json; @@ -59,6 +60,7 @@ int main(int argc, char* argv[]) auto trans_tool = std::make_shared(); trans_tool->set_id(base_info.appID, base_info.secretID); + std::unordered_map word_map; auto trans = [&](const std::string& words, std::string& out) -> bool { std::string request_url = base_info.baseUrl + trans_tool->combine(words, "auto", "en"); std::string response = https->sendGetRequest(request_url); @@ -81,13 +83,22 @@ int main(int argc, char* argv[]) continue; } std::string ret; - std::cout << "翻译:" << line << std::endl; + + if (word_map.count(line)) { + ret = word_map[line]; + vec.emplace_back(TResult{line, ret}); + continue; + } + if (!trans(line, ret)) { vec.emplace_back(TResult{line, "Failed"}); + word_map[line] = "Failed"; } else { vec.emplace_back(TResult{line, ret}); + word_map[line] = ret; } - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::cout << "翻译:" << line << ", 结果:" << ret << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(200)); } in.close();