C++.我想将更改后的特定字符行保存在字符串中
C++. I want to save a specific line of characters, that change, in a string
我通过C++应用程序在CMD中运行一个命令,该应用程序保存该命令的输出。在该输出中,有一个端口号和一个远程API令牌,每次重新启动应用程序im目标时,该令牌都会发生变化。
这是我通过CMD命令得到的输出,我将其存储在字符串中:
"C:/Riot Games/League of Legends/LeagueClientUx.exe" "--riotclient-auth-token=5NFOIOqKB9EfSVsxBMrFUw" "--riotclient-app-port=63498" "--no-rads" "--disable-self-update" "--region=EUW" "--locale=en_GB" "--remoting-auth-token=***vx5yZOk_TkAt9YKq-PEucw***" "--respawn-command=LeagueClient.exe" "--respawn-display-name=League of Legends" "--app-port=63530" "--install-directory=C:Riot GamesLeague of Legends" "--app-name=LeagueClient" "--ux-name=LeagueClientUx" "--ux-helper-name=LeagueClientUxHelper" "--log-dir=LeagueClient Logs" "--crash-reporting=crashpad" "--crash-environment=EUW1" "--crash-pipe=\.pipecrashpad_19692_AJMBMQYOZVYYJMRF" "--app-log-file-path=C:/Riot Games/League of Legends/Logs/LeagueClient Logs/2020-07-09T12-55-09_19692_LeagueClient.log" "--app-pid=19692" "--output-base-dir=C:Riot GamesLeague of Legends" "--no-proxy-server"
我已经尝试过使用regex库的一些东西,并设法将结果拆分为单词,但我仍然不知道如何保存特定的行,即端口号和远程验证authtoken="的结果;我要保存的字符";。
我的代码找出输出字符串中有多少单词:
std::string output = exec("wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline");
std::regex wregex("(\w+)");
auto words_begin = std::sregex_iterator(output.begin(), output.end(), wregex);
auto words_end = std::sregex_iterator();
std::cout << "Found: " << std::distance(words_begin, words_end) << std::endl;
PrintMatch(words_begin, words_end);
输出:
´´
找到:110 CommandLine,C,Riot,Games,League,of,Legends,LeagueClientUx,exe,riotclient,auth,token,5NFOIOqKB9EfSVsxBMrFUw,riotcclient,app,port,63498,no,rads,disable,self,update,region,EUW,locale,en_GB,remoting,auth,´´还有一点,但字符限制限制了我,但我需要存储的输出就在那里。我设置了逗号来标记输出中的新行。
''
这取决于你所说的"保存";。保存到文件还是只分配给变量?我的猜测是,您对迭代器的工作方式感到困惑,并想知道如何从words_begin变量中获取远程身份验证令牌和到的端口号。如果";单词";在cmd中,输出始终与您可以使用的相同:
std::advance(words_begin,16);
std::string port = words_begin->str();
std::advance(words_begin,13);
std::string authToken = words_begin->str();
现在,通常情况下,你会编写regex,以便只匹配你感兴趣的部分;单词";,这取决于远程身份验证令牌和端口号在cmd输出中的位置,如果该输出更改顺序或在前面添加另一个单词,则可能会导致应用程序中断。
相关文章:
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- C++.我想将更改后的特定字符行保存在字符串中
- 为什么签名字符可以保存大于 127 的值?
- 是否可以在 c++ 中将两位数保存在无符号字符中
- Cin 和 getline 无法正确保存非 ascii 字符
- 获取线未将所有字符保存到字符串
- 如何使用 STL C++读取文件和保存连字符
- 键入特殊字符并保存在文件中
- 生成唯一的随机字符并将其保存在数组中
- 将输入保存到字符数组C++
- 无法将 Unicode(希腊语)字符保存到文件中
- 如何保存没有某些字符的字符串
- 如何读取特定的第一个字符并按C++保存数据
- 使用getchar()获取字符并将其保存到每次C 的新行中的文件中
- 在C++中使用字符指针将字符串保存到类属性
- Qt:将QPixmap保存到std::vector<无符号字符>-或者将QByteArray转换为std::
- 如何将二维字符类型数组逐行保存到 c 中的.txt文件中
- 如何在 c++ 中将字节类型的字符数组数据保存到文件中
- 分配字符缓冲区以保存浮点的文本表示形式
- 我的字符数组数组只保存最后输入的行