没有什么特别的点,直接帖结果
#include <stdio.h> #include <iostream> using namespace std; int ia[3][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} }; void OutputWithFor() { cout << "output with for" << endl; for(size_t i = 0;i < 3;i++ ) { for(size_t j = 0;j<4;j++) { cout << ia[i][j] << "\t"; } cout << endl; } } void OutputWithForRange() { cout << "output with for range" << endl; for(int (&innerArray)[4] : ia) { for(int &value : innerArray) { cout << value << "\t"; } cout << endl; } } void OutputWithPoint() { cout << "output with point" << endl; for(int (*innerArray)[4] = begin(ia); innerArray != end(ia);innerArray++) { for(int *value = begin(*innerArray); value != end(*innerArray);value ++ ) { cout << *value << "\t"; } cout << endl; } } int main() { OutputWithFor(); OutputWithForRange(); OutputWithPoint(); }考察类型别名的使用,也没有什么特别的
#include <stdio.h> #include <iostream> using namespace std; // typedef int int_array[4]; using int_array = int[4]; int_array ia[3] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} }; void OutputWithFor() { cout << "output with for" << endl; for(size_t i = 0;i < 3;i++ ) { for(size_t j = 0;j<4;j++) { cout << ia[i][j] << "\t"; } cout << endl; } } void OutputWithForRange() { cout << "output with for range" << endl; for(int_array &innerArray : ia) { for(int &value : innerArray) { cout << value << "\t"; } cout << endl; } } void OutputWithPoint() { cout << "output with point" << endl; for(int_array *innerArray = begin(ia); innerArray != end(ia);innerArray++) { for(int *value = begin(*innerArray); value != end(*innerArray);value ++ ) { cout << *value << "\t"; } cout << endl; } } int main() { OutputWithFor(); OutputWithForRange(); OutputWithPoint(); }直接替换类型就好了
#include <stdio.h> #include <iostream> using namespace std; typedef int int_array[4]; int_array ia[3] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} }; void OutputWithFor() { cout << "output with for" << endl; for(auto i = 0;i < 3;i++ ) { for(auto j = 0;j<4;j++) { cout << ia[i][j] << "\t"; } cout << endl; } } void OutputWithForRange() { cout << "output with for range" << endl; for(auto &innerArray : ia) { for(auto &value : innerArray) { cout << value << "\t"; } cout << endl; } } void OutputWithPoint() { cout << "output with point" << endl; for(auto *innerArray = begin(ia); innerArray != end(ia);innerArray++) { for(auto *value = begin(*innerArray); value != end(*innerArray);value ++ ) { cout << *value << "\t"; } cout << endl; } } int main() { OutputWithFor(); OutputWithForRange(); OutputWithPoint(); }从一开始决定啃C++Pirmer到现在已经过去大半年,原计划今年完成这本书的学习,结果突然工作量爆炸,又跟人合作开发一个小游戏,似乎今年的目标无法达成了,也是很令人蛋疼。 离过年还有两个月,这两个月之内尽可能地完成小游戏的工作,然后继续进行学习吧。