jeudi 8 octobre 2020

How to get all words after comma from csv file in c++

I have a file with course names and list of students that enrolled to this course comma after comma, like this: Course_name,student1,student2,student3

And i want to get each student(student1, student2) to a string in a format "student1 student2 student3 ... student n" with spaces in between and save it as a string( not allowed to use vectors)

i have this starting code, but dont know what to do next

void Courses::viewStudentsByCourseID(){
    string id;
    cou<<"Insert a courseID to see list of students: ";
    cin>>id;
    ifstream infile;
    infile.open("course_students.csv");
    if(infile.is_open()){  
        while(getline(infile, line)) { 
            stringstream sst(line); 
            string courseid;
            
            getline((sst, courseid, ',');
            if (id==courseid) {

            }
            else {
                cout<<"This course has no students listed or it is not exist in database";
            }


        }

    }
    
}

Aucun commentaire:

Enregistrer un commentaire