读取Excel文件
Reading from an Excel file
我试图从一个Excel文件,有四列和121行读取。我尝试了。csv的想法,但我想我理解错了,因为当我编译这个,它变得一团糟。
我怎样才能确保城市是第一个单元格,国家是第二个单元格,城市是第三个单元格,城市是第四个单元格?
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
string city;
string country;
string lat;
string lon;
inFile.open("worldcities.csv");
if (inFile.is_open()) {
cout << "File has been opened" << endl;
}
else {
cout << "NO FILE HAS BEEN OPENED" << endl;
}
while (!inFile.eof()) {
inFile >> city;
inFile >> country;
inFile >> lon;
inFile >> lat;
cout << "City: " << city << endl;
cout << "Country: " << country << endl;
cout << "Lat: " << lat << endl;
cout << "Lon: " << lon << endl;
}
inFile.close();
system("pause");
return 0;
}
试试这个
while (!inFile.eof()) {
getline ( inFile, city, ',' );
getline ( inFile, country, ',' );
getline ( inFile, lat, ',' );
inFile >> lon;
cout << "City: " << city << endl;
cout << "Country: " << country << endl;
cout << "Lat: " << lat << endl;
cout << "Lon: " << lon << endl;
}
相关文章:
- 如何从excel文件中读取数据并存储到变量中?
- 错误写入Excel文件-C++
- C++使用 adodb 在 64 位 Windows 7 中读取 Excel 文件?
- 在C J2ME中读取Excel文件,并从ITQ获取数据
- C Excel加载加载错误:XLL文件由Excel加载为文本文件
- 使用C 在Excel文件中阅读的建议
- 打开现有的 Excel 文件 libxl
- 解析从 Excel 导出Microsoft csv 文件
- 使用 MFC 时导出到 Excel 文件
- 无法从 Excel DLL 中写入文件
- C 如何通过同一MFC应用程序通过System Command打开Excel文件后关闭CMD EXE
- 如何将数据文件加载到自动Excel工作表文档
- 附加相同的加载项,但在 Excel 启动时来自不同的文件夹
- 如何可靠地确定文件是否已在 Microsoft Excel 中打开
- 使用visualstudio在c++中读取excel文件
- 如何用C++将数据写入Excel文件
- 用c++读取excel文件(通用方向)
- 通过读取excel表为c文件中的变量赋值
- Node.JS/C++/Python - 编辑 Excel .xlsx文件
- 如何在 C++ 上使用互操作创建 Excel 文件