积极答复者
for循环里的问题

问题
-
for(std::vector<std::string>::const_iterator it=lines_of_text.begin(),int i=1; it<lines_of_text.end(); it++,i++){ std::cout<<i<<": "<<(*it).c_str()<<std::endl; }
报错:
error C2062: type 'int' unexpected
写成这样就没错:
int i=1; for(std::vector<std::string>::const_iterator it=lines_of_text.begin(); it<lines_of_text.end(); it++,i++){ std::cout<<i<<": "<<(*it).c_str()<<std::endl; }
为什么?
答案
-
在循环里不要定义多个类型,最好都移到循环外,各个编译器标准不同,也不一定都编译通不过
0xBAADF00D- 已标记为答案 Jesse JiangModerator 2011年2月17日 9:43
全部回复
-
额 为什么不把 int i=1放在外面?
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
在循环里不要定义多个类型,最好都移到循环外,各个编译器标准不同,也不一定都编译通不过
0xBAADF00D- 已标记为答案 Jesse JiangModerator 2011年2月17日 9:43