zoukankan      html  css  js  c++  java
  • 《C++ Primer》学习笔记:迭代器介绍

    《C++Primer》(第五版)中,3.4.1的例题中使用一个名为text的字符串向量存放文本文件中的数据,输出text中的内容,刚开始我这样写:

    #include <iostream>
    #include <string>
    #include <vector>
    #include <iterator>
    
    
    using namespace std;
    
    int main(){
        string text("name");
        for (auto it = text.cbegin();
            it != text.cend() && !it ->empty(); ++it)
            cout << *it << endl;
        return 0;
    }

    结果报错:

     error: member reference base type 'const char' is not a structure or
          union

    string text("name");改为 const vector<string> text{"name"};就不会出错了。需要注意的是加上#include<iterator>头文件。

    原因我想可能是const char*指向string对象,但是却不含member function,,后面用到的(*it).empty()class type中需要用到member function,所以才报错。

  • 相关阅读:
    project和task
    Gradle的安装
    Spring 集成 RMI
    RMI远程调用
    安装、启动与基本配置
    删除
    文件的分隔与合并
    my27_OGG MySQL To MySQL错误汇总
    1.5 GO json转Map
    1.4 Go语言-switch语句(转)
  • 原文地址:https://www.cnblogs.com/weixuqin/p/6500995.html
Copyright © 2011-2022 走看看