C++11这次的更新带来了令很多C++程序员期待已久的for range循环
详细见下面例子
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
using namespace std;
int main(int argc, char *argv[])
{
//数组
int strs[5] = {6,4,3,1,2};
for(auto i:strs)
{
std::cout<<i<<endl;
}
//字符串
string str = "wubw test";
for(auto i:str)
{
std::cout<<i<<endl;
}
//容器
std::vector<std::string> vec = {"i", "like", "c++"};
for(auto& it : vec) {
std::cout<<it<<endl;
}
//模板
std::map<int, std::string> myMap = {{1, "c++"}, {2, "java"}, {3, "python"}};
for(auto it : myMap) {
std::cout << it.first << "," << it.second << std::endl;
}
return 0;
}