使用map容器对数字10~15映射英文单词A~F,并在控制台输出
时间: 2024-01-21 19:18:46 浏览: 140
以下是使用map容器对数字10~15映射英文单词A~F的代码:
```cpp
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<int, std::string> myMap;
myMap[10] = "A";
myMap[11] = "B";
myMap[12] = "C";
myMap[13] = "D";
myMap[14] = "E";
myMap[15] = "F";
for (auto it = myMap.begin(); it != myMap.end(); ++it) {
std::cout << it->first << " -> " << it->second << std::endl;
}
return 0;
}
```
控制台输出如下:
```
10 -> A
11 -> B
12 -> C
13 -> D
14 -> E
15 -> F
```
相关问题
使用map容器对数字10~15映射英文单词A~F,并在控制台输出。
以下是使用map容器对数字10~15映射英文单词A~F的示例代码:
```c++
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<int, std::string> myMap{
{10, "A"},
{11, "B"},
{12, "C"},
{13, "D"},
{14, "E"},
{15, "F"}
};
for (const auto& pair : myMap) {
std::cout << pair.first << " -> " << pair.second << '\n';
}
return 0;
}
```
输出结果为:
```
10 -> A
11 -> B
12 -> C
13 -> D
14 -> E
15 -> F
```
阅读全文