C++ unordered_set<string>: 插入字符串
C++ unordered_set: 插入字符串
要将 std::string 插入 std::unordered_setstd::string,可以使用 insert() 函数。以下是一个示例代码:
#include <iostream>
#include <unordered_set>
#include <string>
int main() {
std::unordered_set<std::string> mySet;
std::string str = 'Hello World';
mySet.insert(str);
// 遍历 unordered_set 中的元素
for (const auto &element : mySet) {
std::cout << element << std::endl;
}
return 0;
}
在这个示例中,我们创建了一个 std::unordered_setstd::string 对象 mySet,并且插入了一个 std::string 对象 str。然后,我们使用一个范围 for 循环遍历 unordered_set 中的元素,并将它们打印到标准输出上。
输出结果将为:
Hello World
原文地址: https://www.cveoy.top/t/topic/qaGP 著作权归作者所有。请勿转载和采集!