I want to read a excel file in to a structure.But the thing is it reads the excel columns as whole line.I need those data in columns one by one.Using fstreams I have a file opened that contains numerous columns
I tried it with the knowledge that I have.But It displays all the details as a whole column as i've shown below
Name : Name,Nick
Nick : name,Phone
Phone : number,Carrier,Address
Carrier : Yashodhara,Yash,711256677,Mobitel,"No.
Address : 29,Bollatha,Ganemulla"
-----------------------
Name : Madushani,Madu,711345678,Mobitel,"No.
Nick : 12,
Phone : Gampaha"
Carrier : Sadeepa,Sad,789002264,Hutch,"No.
Address : 123,
-----------------------
I tried this with the following code.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
//structure for store contact details
struct contacts {
string name;
string nickName;
string phoneNumber;
string carrier;
string address;
};
int main() {
const int LIMIT = 10;
contacts limit[LIMIT];
ifstream file;
file.open("Contact.csv");
if (file) {
while (!(file.eof())) {
for (int i = 0; i <= 7; i++) {
file >> limit[i].name;
file >> limit[i].nickName;
file >> limit[i].phoneNumber;
file >> limit[i].carrier;
file >> limit[i].address;
}
}
}
else {
cout << "Error";
}
// Using the following to debug output
for (int i = 0; i < 7; i++) {
cout << "Name : " << limit[i].name << endl
<< "Nick : " << limit[i].nickName << endl
<< "Phone : " << limit[i].phoneNumber << endl
<< "Carrier : " << limit[i].carrier << endl
<< "Address : " << limit[i].address << endl
<< "-----------------------" << endl;
}
return 0;
}
I want to know how to read above details in to the structure in the proper order.