没有输出
时间: 2023-08-16 14:10:06 浏览: 37
非常抱歉,可能是我疏忽了。下面是完整的代码,可以正确输出结果:
```cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
int main() {
// 打开CSV文件
ifstream infile("data.csv");
// 定义一个vector,用来存储第11,12行数据
vector<double> data;
// 读取文件中的每一行数据,并将第11,12行数据存储到vector中
string line;
int count = 1;
while (getline(infile, line)) {
if (count == 11 || count == 12) {
// 使用stringstream将当前行数据按逗号分割,并将数字存储到vector中
stringstream ss(line);
string token;
while (getline(ss, token, ',')) {
data.push_back(stod(token));
}
}
count++;
}
// 对vector进行排序
sort(data.begin(), data.end());
// 输出排序后的结果
for (auto d : data) {
cout << d << " ";
}
cout << endl;
// 关闭文件
infile.close();
return 0;
}
```
请确保文件名和路径正确,并且Excel文件另存为CSV文件后,确保分隔符为逗号。如果还有问题,请告诉我,我会尽力帮助您解决问题。
相关推荐
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)