注册 登录
编程论坛 C++教室

请问如何删除指定的某一行~我弄了很久的没弄出~

炫火 发布于 2011-06-17 22:56, 373 次点击
我这是一个书籍管理的程序,现在我想输入某书号,然后删除该书的信息,但我这程序运行完之后并没有删除信息,请高手帮忙看看。               

                fdat.seekg(0,ios::beg);
                book *a ;
                int n , i , bh ,flag = 0;
                cout<<"需要删除的书号\n";
                cin>>bh;
                fdat.seekg( 0, ios::end );
                long posend = fdat.tellg( );
                n = posend/sizeof(book);
                a = new book [n];
                fdat.seekg( 0, ios::beg);
                i = 0;
                do
                {
                    fdat.read( (char *) & a[i], sizeof(book));
                    i++;
        
                    
                }
                while (  posend!=fdat.tellp() );
                i=0;
                do
                {
                    if( a[i].num == bh)
                    {    cout << "该记录为:" << endl ;
                        cout << "编号:" << a[i].num << endl;
                        cout << "书名:"<< a[i].name << endl ;
                        cout << "出版社:" << a[i].publish << endl ;
                        cout << "作者:"<< a[i].author << endl ;
                        cout << "价格:" << a[i].price << endl ;
                        flag=1;

                        goto L;
                        
                        
                    }
                     fdat.write((char*)&a[i],sizeof(book));
                    L: i++;
                } while (i != n );

                fdat.close();
                fdat.open ( fileDat , ios::binary | ios::in | ios::out ) ;
                delete []a;
                break;
1 回复
#2
炫火2011-06-18 15:22
或者可不可以告诉我删除某行的原理~尽量详细点的~谢谢
1