搜索
查看: 468|回复: 2
打印 上一主题 下一主题

用C++编的迭代器总是报错

[复制链接]
跳转到指定楼层
楼主
发表于 2016-10-3 17:32:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//用gnu总是报错,完全不知道哪里错!!
[mw_shl_code=cpp,true]#pragma GCC diagnostic error "-std=c++11"
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main()
{
    string text("some string");
    for(auto it=text.cbegin();it!=text.cend()&&!it->empty();++it)
        cout<<*it<<endl;
    system("pause");
    return 0;
}

[/mw_shl_code]
沙发
发表于 2017-8-22 12:19:52 | 只看该作者
*it的类型是char,it->empty()等价于(*it).empty(),但是char类型没有empty()函数
板凳
发表于 2017-8-22 18:19:20 | 只看该作者
int main()
{
    string text("some string");
    for(string::iterator it = text.begin(); it != text.end(); ++it)
        cout << *it << endl;
    return 0;
}
这不就可以了吗
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表