_ASSERTE (_BLOCK_TYPE_IS_VALID (pHead-> nBlockUse));

I am working on an assignment that requires me to read data from a text file and store it in different arrays. The first for the loop works fine, but the second for loop throws an error. The console output is correct, but it will prevent me from continuing with my program. What could be causing this?

void ReadFile(){
int totalVideos, cnt, i, custCnt, tempID;
cnt = 0;
custCnt = 0;
i = 0;
Video video[5];
Customer customer[10];
stringstream ss;
ifstream inStream;
inStream.open("Programming Assignment 4 Data.txt");

while(!inStream.eof()){
    string next;
    getline(inStream, next);
    ss<<next;
    ss>>totalVideos;
    for(totalVideos; totalVideos > 0; totalVideos--){
        int copies;
        getline(inStream, next);
        if(next.empty()){
            getline(inStream, next);
        }
        video[cnt].title = next;
        getline(inStream, next);
        video[cnt].star1 = next;
        getline(inStream, next);
        video[cnt].star2 = next;
        getline(inStream, next);
        video[cnt].producer = next;
        getline(inStream, next);
        video[cnt].director = next;
        getline(inStream, next);
        video[cnt].company = next;
        inStream>>copies;
        video[cnt].copies = copies;
        cout<<video[cnt].title<<endl;
        cout<<video[cnt].star1<<endl;
        cout<<video[cnt].star2<<endl;
        cout<<video[cnt].producer<<endl;
        cout<<video[cnt].director<<endl;
        cout<<video[cnt].company<<endl;
        cout<<video[cnt].copies<<endl;
        cout<<endl;
        cnt++;
    }
    for(i; i < 4; i++){
        getline(inStream, next, ',');
        customer[i].firstName = next;
        getline(inStream, next, ',');
        customer[i].lastName = next;
        inStream>>tempID;
        customer[i].id = tempID;
        cout<<customer[i].firstName<<" "<<customer[i].lastName<<" "<<customer[i].id<<endl;
        custCnt++;
    }
}

      

}

EDIT: I changed my main to only contain the following code and it still throws an error

ifstream inStream;
inStream.open("Programming Assignment 4 Data.txt");

while(!inStream.eof()){
    string next = "";
    inStream>>next;
    cout<<next<<endl;
}

      

+3


source to share





All Articles