const_iterator和const iterator的区别
2012-03-27 21:14 Rollen Holt 阅读(635) 评论(0) 编辑 收藏 举报#include <iostream> #include <string> #include<fstream> #include <algorithm> #include <iterator> #include <vector> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { vector<int> myVec; myVec.push_back(0); myVec.push_back(1); myVec.push_back(2); copy( myVec.begin(),myVec.end(),ostream_iterator<int>( cout," " )); cout<<endl; const vector<int>::iterator cite = myVec.begin(); *cite = 10; //可行 //++cite; //错啦错误 copy( myVec.begin(),myVec.end(),ostream_iterator<int>( cout," " )); cout<<endl; vector<int>::const_iterator icte = myVec.begin(); // *icte = 100; //error C3892: “icte”: 不能给常量赋值 ++icte; //可行 copy( myVec.begin(),myVec.end(),ostream_iterator<int>( cout," " )); cout<<endl; return 0; }
==============================================================================
本博客已经废弃,不在维护。新博客地址:http://wenchao.ren
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员
==============================================================================