I am running into problems reading in a csv file. I have an inventory.csv file with three columns and around 10,000 rows. The last column is supposed to be ignored. The csv format looks like this
Shelf number; item name; item number. (So here item number shall be ignored).
After reading from user input (user has a choice to enter either the code or item name), I want to display both the shelf number and item name from the inventory csv list. This is for my Uni assignment, and I am not allowed to use any boost or tokeniser classes. Just getline and other basic commands. In addition enumerated type structure with the two values, shelf number and item name, and a structure to build a list (with char * and a pointer to the next element of the list) shall be included. This makes me understand it harder. So far this is how much I understand ,to read one line after a user inputs a line number. Here is the code :
fstream& read_line(fstream& file, unsigned int num)
{
file.seekg(ios::beg);
for(unsigned int i=0; i < num - 1; ++i)
file.ignore(numeric_limits<streamsize>::max(),'\n');
return file;
}
int main()
{
fstream file("care_icd10_en.csv",ios_base::in);
if (!file)
cout << "Unable to open file \n";
else
{
int line_number;
cout<< "Please enter a line :"<<endl;
cin >>line_number;
read_line(file, line_number);
if (!file)
cout << "Wrong line number : " << line_number;
else
{
string line;
getline(file,line);
cout <<line<<endl;
cout << "Search again..";
}
}
return 0;
}
your help is appreciated! Thanks a lot!