我有以下代码
#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;
}
但它会导致编译器错误,提示“my is undefined”。怎么了?
最佳答案
你需要在字符串后面放一个分号而不是冒号。
string d="georgia is nice country"; // <-- semicolon!
关于c++ - 关于字符串迭代器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3218304/