关于字符串迭代器的问题

时间:2010-07-10 07:33:54

标签: c++

我有以下代码

#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;
}

但它会导致编译器错误,说“我的未定义”。有什么问题?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

你需要在字符串后加一个分号而不是冒号。

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