zoukankan      html  css  js  c++  java
  • 《C++ Primer》学习笔记:向vector对象添加元素蕴含的编程假定

    练习《C++ Primer》中的3.14节时,当敲入:

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(){
        string word;
        vector<string> text;
        while (cin >> word)
            text.push_back(word);
        return 0;
    }

    程序会报错:

    error: use of undeclared identifier 'vector'

    其实应该插入一行:

    #include <vector>

    变成:

    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    int main(){
        string word;
        vector<string> text;
        while (cin >> word)
            text.push_back(word);
        return 0;
    }

    才不会报错。

    需要注意的是vector需要使用命名空间std,所以需要键入std::vector或在开头敲入using namespace std;

  • 相关阅读:
    MM and Desinger
    db subsequent and synchronization(transfer)
    Thread concepts
    Threads concepts
    lucene article
    primary key
    lucene
    page procedure
    connection pool
    page procedures
  • 原文地址:https://www.cnblogs.com/weixuqin/p/6481502.html
Copyright © 2011-2022 走看看