std::sub_match<BidirIt>::operator string_type, std::sub_match<BidirIt>::str
來自 cppreference.com
operator string_type() const; |
(1) | |
string_type str() const; |
(2) | |
轉換為底層 std::basic_string 型別的物件。
1) 隱式轉換。
2) 顯式轉換。
[編輯] 返回值
作為底層 std::basic_string 型別的物件的匹配字元序列。如果 matched
成員為 false,則返回空字串。
[編輯] 複雜度
與底層字元序列的長度呈線性關係。
[編輯] 示例
執行此程式碼
#include <cassert> #include <iostream> #include <regex> #include <string> int main() { const std::string html{R"("<a href="https://cppreference.tw/">)"}; const std::regex re{"(http|https|ftp)://([a-z]+)\\.([a-z]{3})"}; std::smatch parts; std::regex_search(html, parts, re); for (std::ssub_match const& sub : parts) { const std::string s = sub; // (1) implicit conversion assert(s == sub.str()); // (2) std::cout << s << '\n'; } }
輸出
https://cppreference.tw https cppreference com