From 8142ecd3fadfa2df3983e080671c006a2684e153 Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 12 Mar 2026 23:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 ++++- ReplaceStr/main.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfeb9d2..a78da3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,4 +12,7 @@ endif() find_package(Boost REQUIRED) -add_subdirectory(ReplaceStr) \ No newline at end of file +add_subdirectory(ReplaceStr) +target_link_libraries(ReplaceStr PRIVATE + Boost::headers +) \ No newline at end of file diff --git a/ReplaceStr/main.cpp b/ReplaceStr/main.cpp index 470a39d..ebc1fea 100644 --- a/ReplaceStr/main.cpp +++ b/ReplaceStr/main.cpp @@ -1,6 +1,54 @@ +#include #include +#include +#include + +#ifdef _WIN32 +#include +#endif + +struct OneItem { + std::string from; + std::string middle; + std::string to; +}; + +void testFun() +{ + std::vector testConfig; + testConfig.push_back({"Rcp15", "RcpBX5", "Rcp5"}); + testConfig.push_back({"Rcp7", "RcpBX4", "Rcp4"}); + testConfig.push_back({"Rcp3", "RcpBX3", "Rcp3"}); + testConfig.push_back({"Rcp1", "RcpBX2", "Rcp2"}); + testConfig.push_back({"Rcp0", "RcpBX1", "Rcp1"}); + + std::string testData = + R"( +这是一个测试文件,Rcp15,Rcp7,Rcp3,Rcp1,Rcp0。 +Rcp15,Rcp7,Rcp3,Rcp1,Rcp0。 +)"; + + std::cout << testData << std::endl; + std::cout << "" << std::endl; + + for (const auto& item : testConfig) { + boost::replace_all(testData, item.from, item.middle); + } + for (const auto& item : testConfig) { + boost::replace_all(testData, item.middle, item.to); + } + + std::cout << testData << std::endl; + std::cout << "" << std::endl; +} + +int main() +{ +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif + testFun(); -int main() { std::cout << "Hello World!" << std::endl; return 0; } \ No newline at end of file