Usuwanie rekordu z ostatniej linijki!

0
class Make{

	string name;
	int mark,amount;
	string name2;			
	public:
	Make(){
	}
	
	void Tworz(){
	
		cout<<"Podaj nazwę bazy danych"<<endl;
		cin>>name;
		fstream compare;
		compare.open("Baza", ios::in);					//Sprawdza czy podana nazwa już nie istnieje
		while(getline(compare,name2)){
			if(name==name2){
			cout<<"Podana nazwa już istnieje"<<endl;
			compare.close();
			cin.ignore();
			cin.get();		
			return;
			}
		}
		compare.close();	                    					
		fstream File;
		File.open("Baza", ios::out| ios::app);				//Nazwy bazy danych
		File<<name<<endl;
		File.close();
	
		cout<<"Podaj ilość kolumn"<<endl;
		cin>>mark;
		fstream File2;
		File2.open(("Columns-"+name).c_str(), ios::out);
		File2<<mark<<endl;
		cout<<"Podaj nazwy dla kolumn o ilosci: "<<mark<<endl;
		cin.ignore();
		for(int i=1;i<=mark;i++){					//i=1,ponieważ jeżeli i=0 to byśmy zaczynali od kolumny 											zerowej a jej nie ma
		cout<<"Podaj nazwe dla kolumny numer: "<<i<<endl;
		getline(cin,name2);
		File2<<name2<<endl;
		}
		File2.close();
	}
	void Record(){

		cout<<"Na jakiej bazie chcesz operowac?"<<endl;
		fstream loadFile;
		loadFile.open("Baza", ios::in);
		while(getline(loadFile,name2)){
			cout<<name2<<" "<<endl;	
		}
		loadFile.close();
		cin>>name;
		fstream checkExist;					
		checkExist.open("Baza", ios::in);
		while(getline(checkExist,name2)){
			if(!(name2==name)){
			cout<<"Nie istnieje taki plik"<<endl;
			checkExist.close();
			cin.ignore();
			cin.get();		
			return;
			}
		}
		checkExist.close();		
		cout<<"Podaj ilość rekordów do dodania"<<endl;
		cin>>amount;
		fstream Pobierz;
		Pobierz.open(("Columns-"+name).c_str(), ios::in);
		string columnsValue;
		getline(Pobierz,columnsValue);
		int newMark=atoi(columnsValue.c_str());
		fstream Records;
		Records.open(("Records-"+name).c_str(), ios::out|ios::app);		
		cin.ignore();				
		for(int i=0;i<amount;i++){						//for do ilosci rekordow
			cout<<"Podaj dane dla rekordu numer: "<<i<<endl;
			for(int j=0;j<newMark;j++){					//for do ilosci slow w rekordach	
				cout<<"Podaj slowo "<<endl;			
				getline(cin,name2);
				Records<<name2<<endl;
			}
		}
		Pobierz.close();
		Records.close();
	}
				
	void Show(){
		cout<<"Ktora baze danych chcesz wyswietlic: ";
		fstream view;
		view.open("Baza", ios::in);
		while(getline(view,name2)){
		cout<<name2<<" ";	
		}
		view.close();	
		cin>>name;
		fstream checkExistation;					
		checkExistation.open("Baza", ios::in);
		while(getline(checkExistation,name2)){
			if(!(name==name2)){
			cout<<"Nie istnieje taki plik"<<endl;
			checkExistation.close();	
			cin.ignore();	
			cin.get();
			return;
			}
		}
		checkExistation.close();
		fstream showDatabase;
		showDatabase.open(("Columns-"+name).c_str(), ios::in);
		fstream showDatabaseRecords;
		showDatabaseRecords.open(("Records-"+name).c_str(), ios::in);
		system("clear");
		cout<<"Baza danych: "<<name<<endl;
		getline(showDatabase,name);
		int showMark=atoi(name.c_str());			//Atoi-zmienia stringa na inta.
		while(getline(showDatabase,name)){
			cout<<name<<"	";
		}
		cout<<"	"<<endl;
		while(getline(showDatabaseRecords,name)){
			for(int a=0; a<showMark; a++){
				getline(showDatabaseRecords,name);
				cout<<name<<"	";
			}
			cout<<"	"<<endl;
		}
		cin.ignore();
		cin.get();
		showDatabaseRecords.close();
		showDatabase.close();
	}	
			
};

Witam wrzuciem tutaj jeden z swoich plikow mojej bazy danych. Jest problem taki iz nie wyswietla ostatniej linijki rekordkow (np jak podam 3 rekordy to wyswietla tylko 2) itd.

1
while(getline(showDatabaseRecords,name)){
            for(int a=0; a<showMark; a++){
                getline(showDatabaseRecords,name);
                cout<<name<<"   ";
            }
            cout<<" "<<endl;
        }

Pobierasz pierwszą linie z pliku w warunku petli while i nic z nią nie robisz, a później pobierasz pozostałe linie w pętli for. Odczyt całego pliku zrób w jednej pętli.

1 użytkowników online, w tym zalogowanych: 0, gości: 1