Bar*_*ers 2 c++ dictionary cout std
我有一张地图声明如下
map<string, int> symbolTable;
if(tempLine.substr(0,1) == "("){
symbolTable.insert(pair<string, int>(tempLine, lineCount));
}
Run Code Online (Sandbox Code Playgroud)
我如何std::cout符号表中的所有内容?
在现代 C++ 中:
for (auto&& item : symbolTable)
cout << item.first << ": " << item.second << '\n';
Run Code Online (Sandbox Code Playgroud)
如果您只能访问 C++11 之前的编译器,则代码将是:
for ( map<string, int>::const_iterator it = symbolTable.begin(); it != symbolTable.end(); ++it)
cout << it->first << ": " << it->second << '\n';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2404 次 |
| 最近记录: |