2010-07-10 138 views
0

我有下面的代碼問題迭代器

#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://stackoverflow.com/questions/2879555/c-stl-how-to-write-wrappers-for-cout-cerr-cin-and-endl/2880136#2880136)爲什麼這是_不是一個好主意。 – sbi 2010-07-10 10:09:05

回答

1

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

string d="georgia is nice country"; // <-- semicolon! 
1
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