标签:npos pos ring class get string use firefox root
#include <string> #include <sstream> #include <iostream> int main() { std::wstring keyname = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Mozilla\\Firefox"; std::wstring root, key; std::wistringstream iss(keyname); if (std::getline(iss, root, L‘\\‘) && std::getline(iss, key)) { std::wcout<<root<<" "<<key; } }
输出:
HKEY_LOCAL_MACHINE SOFTWARE\Mozilla\Firefox
另一种方法:
#include <string> std::wstring keyname = ...; // "HKEY_LOCAL_MACHINE\\SOFTWARE\\Mozilla\\Firefox" std::wstring::size_type pos = keyname.find(L‘\\‘); if (pos != std::wstring::npos) { std::wstring root = keyname.substr(0, pos); std::wstring key = keyname.substr(pos+1); // use root and key as needed... }
标签:npos pos ring class get string use firefox root
原文地址:https://www.cnblogs.com/strive-sun/p/13097804.html