i can’t get value in line with the text.
The csv you have shown would be
,,,
First name,Last name,Course,section
Jan,Orzeg-Wydra,IT,Comp
First name,Last name,Course,section
Sam,tyy,IT,City
And getline
reads a line so the first iteration would be
first_name = "";
last_name = "";
course = "";
section = "";
Then
first_name = "First name";
last_name = "Last name";
course = "Course";
section = "section";
And so on and so forth. So your code is working as expected.
Also please don’t tag Ben as he’s far too busy handling the company.
Also don’t bump threads that are only an hour old. I go through the Q&A and the Ask subforum daily. If you don’t get a response in 48 hours, feel free to bump.
can you have a look at the .exe that’s what is wrong and sorry
Are you sure the contents of the file is correct? Also not a different file with similar contents?
yes and it’s the same file
Actually looking at it closer that’s still working as expected. What are you expecting?
Name: Jan Orzeg-Wydra
Course: IT
Section: computer
Name: Sam Orzeg-Wydra
Course: IT
Section: computer
Name: Harry Orzeg-Wydra
Course: IT
Section: computer
I explained in my initial reply that this isn’t what would happen. You’re reading lines hence the name getline
.
Probably the easiest way is to use a library e.g.
https://github.com/p-ranav/csv2
Otherwise you’re going to have to write your own csv parser.
On a sidenote global variables are discouraged and those don’t seem like exceptions to that rule.