在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
c++11新增的容器1:array #include <string> #include <iterator> #include <iostream> #include <algorithm> #include <array> int main() { // construction uses aggregate initialization std::array<int, 3> a1{ {1, 2, 3} }; // double-braces required in C++11 (not in C++14) std::array<int, 3> a2 = {1, 2, 3}; // never required after = std::array<std::string, 2> a3 = { std::string("a"), "b" }; // container operations are supported std::sort(a1.begin(), a1.end()); std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; // ranged for loop is supported for(const auto& s: a3) std::cout << s << ' '; } c++11中新增的容器:unordered_map unordered_set #include <iostream> #include <string> #include <unordered_map> int main() { // Create an unordered_map of three strings (that map to strings) std::unordered_map<std::string, std::string> u = { {"RED","#FF0000"}, {"GREEN","#00FF00"}, {"BLUE","#0000FF"} }; // Iterate and print keys and values of unordered_map for( const auto& n : u ) { std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n"; } // Add two new entries to the unordered_map u["BLACK"] = "#000000"; u["WHITE"] = "#FFFFFF"; // Output values by key std::cout << "The HEX of color RED is:[" << u["RED"] << "]\n"; std::cout << "The HEX of color BLACK is:[" << u["BLACK"] << "]\n"; return 0; } c++11中新增的容器:非成员begin\end #include <iostream> #include <vector> #include <iterator> int main() { std::vector<int> v = { 3, 1, 4 }; auto vi = std::begin(v); std::cout << *vi << '\n'; int a[] = { -5, 10, 15 }; auto ai = std::begin(a); std::cout << *ai << '\n'; }
abelkhan技术论坛:http://abelkhan.com/forum.php,欢迎大家交流技术 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论