_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead-> nBlockUse));

时间:2014-11-29 22:44:20

标签: c++ pointers file-io

我正在进行一项任务,要求我从文本文件中读取数据并将其存储到不同的数组中。第一个for循环工作完全正常,但第二个for循环导致错误。控制台输出是正确的,但它不会让我继续我的程序。可能导致这种情况的原因是什么?

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++;
    }
}

}

编辑:我已将主要内容更改为仅包含以下代码,但仍会引发错误?

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

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

0 个答案:

没有答案