void hotFood() { cout << "外卖id\t添加次数\t外卖名称" << endl; vector<pair<int, int>> countVec(countMap.begin(), countMap.end()); sort(countVec.begin(), countVec.end(), [](const pair<int, int>& a, const pair<int, int>& b) { return a.second > b.second; }); int count = 0; for (auto it = countVec.begin(); it != countVec.end() && count < 3; it++, count++) { int id = it->first; int count = it->second; cout << id << "\t" << count << "\t" << foods[id].getName().c_str() << endl; } //保存统计结果 save(countVec, "count.dat"); }如何将这个函数输出的结果通过上面我给的save函数保存下来
时间: 2024-03-16 13:48:04 浏览: 19
要将这个函数的输出结果保存下来,可以在函数末尾调用 save 函数,并将 countVec 作为参数传给它。代码如下:
```
void hotFood() {
cout << "外卖id\t添加次数\t外卖名称" << endl;
vector<pair<int, int>> countVec(countMap.begin(), countMap.end());
sort(countVec.begin(), countVec.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
return a.second > b.second;
});
int count = 0;
for (auto it = countVec.begin(); it != countVec.end() && count < 3; it++, count++) {
int id = it->first;
int count = it->second;
cout << id << "\t" << count << "\t" << foods[id].getName().c_str() << endl;
}
// 保存统计结果
save(countVec, "count.dat");
}
```
其中,`save` 函数应该已经在你的代码中实现了。注意,这里的保存路径是 `"count.dat"`,你可以根据需要修改。
相关推荐
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)