All pastes #38468 Raw Edit

Anonymous

public unlisted text v1 · immutable
#38468 ·published 2006-01-25 00:34 UTC
rendered paste body

#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

typedef struct {
        string ClassNumber;
        string ClassName;
} StudentCInfo;

typedef struct {
        string ID;
        string LastName;
        string FirstName;
        string Address;
        string City;
        string State;
        string Zip;
        string Age;
        string Sex;
        string WorkTime;
        vector<StudentCInfo> Classes;
} StudentPInfo;

string ReadCompleteFile(string NameOfFile)
{
    string sBuff;	
    char *buff = NULL;
    long lSize = 0;
    fstream FileIn;
    
    FileIn.open (NameOfFile.c_str(), ios::in|ios::binary|ios::ate);
    if(!FileIn.fail())
    {
        lSize = FileIn.tellg();
        FileIn.seekg (0, ios::beg);
        buff = new char [lSize+1];
        FileIn.read (buff, lSize);
        buff[lSize] = '\0';
        sBuff = buff;
    }
    
    else {
        sBuff.assign("Unable to read file \'" + NameOfFile+ "\'");
    }
    FileIn.close();
    
    delete buff;
    return sBuff;
}

int main(void)
{
    //std::string s = "hello\nworld";  std::cout << (s.find('\n') == std::string::npos) << std:: endl; 
    string sInput;
    StudentPInfo studenttest[5];
    //StudentCInfo studentinfo[13];
    
    int i;
    int k[3] = {0};
    sInput = ReadCompleteFile("student.txt");
  //  do{
 
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].ID = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].LastName = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].FirstName = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].Address = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].City = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].State = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].Zip = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].Age = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          studenttest[0].Sex = sInput.substr(k[0]+1, (k[1]-k[0])-1);

          k[0] = sInput.find(",",k[1]);
          k[1] = sInput.find(",", k[0]+1);
          k[2] = sInput.find('\n'); /////////////////////////////RIGHT HERE
//////////////////////////RETURNING NPOS!!!
          studenttest[0].WorkTime = sInput.substr(k[0]+1, (k[1]-k[0])-1);
          
          //for(i=k[0];i <= k[1]; i++ )cout << int(studenttest[0].WorkTime[i]) << " ";
          //if(sInput[i] == )
          cout << studenttest[0].ID << endl;
          cout << studenttest[0].LastName << endl;
          cout << studenttest[0].FirstName << endl;
          cout << studenttest[0].Address << endl;
          cout << studenttest[0].City << endl;
          cout << studenttest[0].State << endl;
          cout << studenttest[0].Zip << endl;
          cout << studenttest[0].Age << endl;
          cout << studenttest[0].Sex << endl;
          cout << studenttest[0].WorkTime << endl;
               
          //for ()
          //if(studenttest[i].Sex == 'F')
          
//}while(1);
    getchar();
	return 0;
}


/* FILE - student.txt//////////////////////////
S,123456,Doe,Jane,1122 SW 8th Street,Miami,FL,33111,18,F,F/T
U,CGS2405,ADVANCED C++
U,ENC1101,BASIC ENGLISH
U,BRB1100,BE RIGHT BACK
S,233456,James,Steven,11322 NW 112th Street,Tallahassee,FL,33121,21,M,F/T
U,CGS2405,ADVANCED C++
U,ENC1102,ADVANCED ENGLISH
U,BRB1101,CAME RIGHT BACK
S,345346,Kyle,Bone,2401 SE 12th Ave,Pensacola,FL,33001,22,M,P/T
U,CGS2405,ADVANCED C++
U,SCI1101,BASIC SCIENCE
U,BRB1100,BE RIGHT BACK
S,123456,Xmas,Mary,1201 SW 97th Street,Orlando,FL,33111,18,F,P/T
U,CGS2405,ADVANCED C++
U,QRP1101,WRITING PROPOSALS
U,BRB1100,BE RIGHT BACK
U,BRB1101,CAME RIGHT BACK
S,123456,Jefferson,John,11223 NW 83th Court,Jacksonville,FL,33100,19,M,F/T
U,CGS2405,ADVANCED C++
U,SCI4101,ADVANCED ENGLISH
U,RGP1100,INTRO TO ROCKET PROPELLED GRENADES
S,123456,Richardson,Beth,8763 SW 18th Terrace,Tampa,FL,32101,18,F,F/T
U,CGS2405,ADVANCED C++
U,ENC1101,BASIC ENGLISH
U,BRB1100,BE RIGHT BACK
*\ END OF FILE