versuche gerade ein Programm zu schreiben um 10 Studentennamen aus einer csv mit csvread zu holen . Aber irgendwie kann oder sieht Compiler diese nicht .

hier ist mein Code:
Code: Alles auswählen
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
struct Student
{
string firstname;
string lastname;
char sex;
int matriculation_number;
float final_mark;
};
Student students[10];
ifstream csvread;
csvread.open("data.csv", ios::in);
if (csvread)
{
string s = "";
int counter_field = 0;
int counter_student = 0;
while (getline(csvread, s, ';'))
{
if (counter_field == 0)
students[counter_student].firstname = s;
if (counter_field == 1)
students[counter_student].lastname = s;
if (counter_field == 2)
students[counter_student].sex = s.at(0);
if (counter_field == 3)
students[counter_student].matriculation_number = atoi(s.c_str());
if (counter_field == 4)
students[counter_student].final_mark = atof(s.c_str());
counter_field++;
if (counter_field > 4)
{
counter_field = 0;
counter_student++;
}
}
csvread.close();
}
else
{
cout << "Fehler beim Lesen!" << endl;
}
for (int i = 0; i < 10; i++)
{
cout << "Student " << i << endl;
cout << " Firstname => " << students[i].firstname << endl;
cout << " Lastname => " << students[i].lastname << endl;
cout << " Sex => " << students[i].sex << endl;
cout << " Matriculation Number => " << students[i].matriculation_number << endl;
cout << " Final mark => " << students[i].final_mark << endl;
cout << endl << endl;
}
return 0;

Edit by Xin: Codetags hinzugefügt