c++11 基於範圍的for循環
阿新 • • 發佈:2017-11-05
基於 out int 無法找到 span 編譯器 for循環 ++ define
c++11 基於範圍的for循環
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <vector> #include <map> int func(int a[]) // 形參中數組是指針變量,無法確定元素個數 { for (auto e: a) // err, 編譯失敗, 無法找到合適的begin函數 { std::cout << e << " " } std::cout<< std::endl; } void mytest() { int a[5] = {1,2,3,4,5}; // 使用基於範圍的for循環 for (int & e: a) { e *= 2; } for (int & e: a) { std::cout << e << " "; } std::cout << std::endl; // 導致內部編譯器錯誤 func(a); return; } intmain() { mytest(); system("pause"); return 0; }
c++11 基於範圍的for循環