+ 2

How to read a csv file with 3 columns of datai.e. name, ID and mark? After reading the data,how can we convert the mark as grade

assignment

21st May 2018, 1:47 AM
Shivneet Prasad
Shivneet Prasad - avatar
3 Réponses
+ 2
A csv file contains values seperated by commas. So all you need to do is use a getline call to read a row from a csv file into a string, then replace all commas present in the row with spaces, and then read the row data (stored as a string) into your class members via istringstream or sscanf. Then, you can convert marks to grade by calculating percentage and then using an if-else block to assign or return the respective grade.
21st May 2018, 2:33 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
SQrL C++ lacks a split function unlike other languages. So, the best bet is to use stringstream. But we do have a way to split a string into iterators using regex.
22nd May 2018, 6:31 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
Does C++ have a string split so you can break each row into 3 parts based on where the commas are? If so, I would recommend this approach over conversion of comma to space.
22nd May 2018, 6:28 AM
SQrL
SQrL - avatar