问题迭代器

问题描述:

我有下面的代码问题迭代器

#include <iostream> 
#include <string> 
#include <algorithm> 

using namespace std; 

int main(){ 
    string d="georgia is nice country": 
    string::iterator my; 
    for (my=d.begin();my!=d.end();my++) { 
    cout<<*my<<endl; 
    } 
    return 0; 
} 

但它会导致编译器错误说:“我不确定”。哪里不对?

+0

抱歉,我已经看到了我的错误 – 2010-07-10 07:36:17

+0

如果有人想要的答案后,我会接受它 – 2010-07-10 07:36:54

+0

'使用命名空间std;'这是节省您键入每次五个字符从标准库输入一个标识符。看到[这个答案](http://*.com/questions/2879555/c-stl-how-to-write-wrappers-for-cout-cerr-cin-and-endl/2880136#2880136)为什么这是_不是一个好主意。 – sbi 2010-07-10 10:09:05

您需要在字符串后面加上分号而不是冒号。

string d="georgia is nice country"; // <-- semicolon! 

string d="georgia is nice country"; // <-- semicolon, not colon 
+0

我想了一会儿你说格鲁吉亚不是一个好国家。 – Borealid 2010-07-10 07:38:58

+0

没有格鲁吉亚是非常好的国家 – 2010-07-10 07:43:02

+0

只是在这里有点可怜的生活位一切都会好起来 – 2010-07-10 07:43:36