Horje
how to read a comma delimited file into an array c++ Code Example
how to read a comma delimited file into an array c++
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>

int main()
{
    std::ifstream inFile("registration.txt");
    if (inFile.is_open())
    {
        std::string line;
        while( std::getline(inFile,line) )
        {
            std::stringstream ss(line);

            std::string ID, fname, lname;
            std::getline(ss,ID,',');    std::cout<<"\""<<ID<<"\"";
            std::getline(ss,fname,','); std::cout<<", \""<<fname<<"\"";
            std::getline(ss,lname,','); std::cout<<", \""<<lname<<"\"";

            std::vector<std::string> enrolled;
            std::string course;
            while( std::getline(ss,course,',') )
            {
                 enrolled.push_back(course); std::cout<<", \""<<course<<"\"";
            }
            std::cout<<"\n";
        }
    }
    return 0;
}




Cpp

Related
function overloading in c++ Code Example function overloading in c++ Code Example
c++ hours minutes seconds Code Example c++ hours minutes seconds Code Example
how print fload wiht 3 decimal in c++ Code Example how print fload wiht 3 decimal in c++ Code Example
c++ map iterator Code Example c++ map iterator Code Example
switch case with string c++ Code Example switch case with string c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8