错误:'list'不是'std'的成员而且error:template参数2无效

New*_*his 8 c++ dictionary list std c++11

我正在尝试编译我的头文件,但是我遇到了我无法弄清楚的错误.

我想创建一个包含3个地图的结构:-map从单个单词到count -map从单词对到count -map从单个单词到下面单词列表

我的头文件中的代码:

#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map>

typedef struct {

    std::map<std::string, int> firstCounts;
    std::map<std::string, int> pairCounts;
    std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 

} LanguageModel;
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

>   LangModel.h:24:23: error: ‘list’ is not a member of ‘std’
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 
>                            ^
>     LangModel.h:24:23: error: ‘list’ is not a member of ‘std’
>     LangModel.h:24:38: error: template argument 2 is invalid
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 
>                                           ^
>     LangModel.h:24:38: error: template argument 4 is invalid
>     LangModel.h:24:44: error: expected unqualified-id before ‘>’ token
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list.
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 15

你忘了添加

#include <list>    
Run Code Online (Sandbox Code Playgroud)

  • 在 `.h` 文件中添加 `#include` 行会产生编译时间成本。除非你需要,否则不要在 `.h` 文件中`#include` 任何东西。 (2认同)

cad*_*luk 5

#include <list>呢 您缺少标题包含。