0
      string comma;
 92   string line;
 93   ifstream myfile("student.dat");
 94   string name,email="";
 95   string status="";
 96   int id;
 97   if (myfile.is_open()){
 98     while ( getline (myfile,line) ) {
 99         //parse line
100         string myText(line);
101        // cout<<line<<endl;
102         istringstream iss(myText);
103         if (!(iss>>id)) id=0;
104         Student newStudent(id,line,"","");
105         Student::studentList.insert(std::pair<int,Student>(id,newStudent));
106     }

Line 104 does not quite accomplish what I desire.

 public:
     19         static Student findStudent(int ID);
     20         static map<int,Student> studentList;
     21         Student(int ID, string name, string gradeStatus,string     email):Id(ID),name(name),status(gradeStatus),emailAddress(email){};

Above is where the constructor is defined. I am lost on how to parse the string and then apply each piece as parameters.

Also here is an example line from the file: 0,0,person name,freshman,email@stuff.com

user3341518
  • 47
  • 1
  • 1
  • 6
  • @0x499602D2 I rolled back your edit because if you remove the line numbers, it is not clear what "Line 104" in the sentence directly below the code refers to. –  Feb 22 '14 at 19:58
  • Essentially, what you seem to be asking for is how to split your line "0,0,person name,freshman,email@stuff.com" into separate fields, using the comma as a field separator. This has been asked many times before. (I say that without blame, it can be hard to know what to search for.) –  Feb 22 '14 at 20:00
  • Ya it just dawned on me the ,"","" is actually two empty strings. That is one reason I have had such a hard time figuring out why the constructor call still worked. – user3341518 Feb 22 '14 at 20:06
  • You can put `line` into an `std::istringstream`, extract into the appropriate types and then send them to the constructor call. – David G Feb 22 '14 at 20:12

0 Answers0