我正在尝试读取一个有四列和121行的Excel文件。我尝试了.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;
}