#include <iostream>
#include <string>
#include <sstream>
using namespace std;

const size_t SIZE=256;

int main() {
	int rank;
	string names, grades;
//	int grades[SIZE];

	istringstream inFile{"125 {John_BROWN_Biology} {100_81}\n245 {Amanda_SMITH_Chemistry} {83_74}\n436 {Michael_CLARK_Calculus} {35_48}"}; //!!
	//inFile.open("records.txt");
	string line;
	
	while (getline(inFile, line))   // red line by line 
	{
		stringstream sst{line};    // then parse the stream
	    char delim;  
	    
		sst>>rank;  				// read an integer
		sst>>delim; 				// skip white and read a single char 
		if (delim!='{') {
			cout<<"Error on line: { expected for name instead of "<<delim<<endl; 
			continue;   // next line, please !! 
		}
		getline(sst,names, '}');  // TO DO: error handling
		sst>>delim; 
		if (delim!='{') {
			cout<<"Error on line: { expected for grades instead of "<<delim<<endl; 
			continue;   // next line, please !! 
		}
		getline(sst,grades, '}');  // TO DO: error handling
		
		cout << rank<<" "<<names<<" "<<grades<<endl; 

	}
/*	int i=0, j=0;
	while (!inFile.getline((char*)&rank, 30, '{'){
	    inFile.getline(st_info, SIZE, '_');
	    inFile.getline(words_array, SIZE, '_');
	}
	while (!success1)
	{
	    getline(inFile,Line,'{'); // get values for info array
	    stringstream iss1; 
	    iss1 << Line; //Put the string into a stream
	    iss1 >> rank; //To send data as an int.
	    cout << "STUDENT NUMBER:" << rank << "  ";
	    while (!success2){
	    // for the info in {} part
        	getline(inFile,Line,'_'); 
        	stringstream iss; 
        	iss << Line; 
        	iss >> st_info[i];
        	cout <<"STUDENT INFO:" << st_info[i] << "   ";
        	i++;
        	if (getline(inFile,Line,'}')){
	            stringstream iss2; 
            	iss2 << Line; 
            	iss2 >> st_info[i];
            	cout << st_info[i] << " ";
            	i=0;
            	success2 = true;
        	}
    	}
    	getline(inFile,Line,'{'); 
    	stringstream iss3; 
    	iss3 << Line; 
    	iss3 >> grades[j]; 
    	cout << "GRADES: "<< grades[i] << " ";
    	j++;
    	while (!success3){
	        getline(inFile,Line,'_');
        	stringstream iss4; 
        	iss4 << Line;
        	iss4 >> grades[j];
        	cout << grades[i] << "  ";
        	j++;
        	if (getline(inFile,Line,'}')){
	            stringstream iss5; 
            	iss5 << Line;
            	iss5 >> grades[j];
            	cout << grades[i] << "  ";
            	j=0;
            	success3 = true;
        	}
    	}
	} */
}