stdunordered_setstdstring插入stdstring
要将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/is6v 著作权归作者所有。请勿转载和采集!