字符串,向量和数组中的易错点

	while (cin >> word){
		cout << endl;
	}
        cin>>word;
在输入Ctrl+Z后,后面的输入就都不能接受到数据了。
 
在string s;中s.empty();是意味着S为空及s==””;而不能将s=NULL;是错的。
 
在vector中注意基本是函数的调用。
 
  1. iterator 中的begin和end
for (auto &i:ia)
    for (auto &j : i){
        j = cnt;
        cnt++;
    }

要使用范围for语句处理多维数组,除了最内层的循环外,其它所有循环的控制变量都应该是引用类型。

1.迭代器在二维数组中的使用。

    const size_t row = 3, col = 4;
    int ia[row][col];
    for (auto p = begin(ia); p != end(ia); p++){
        for (auto q = begin(*p); q != end(*p); q++){
            cout << *q << "  ";
        }
        cout << endl;
    }
posted @ 2015-08-19 10:24  karel  阅读(222)  评论(0编辑  收藏  举报