Witam! Mam sobie prosty programik. Ma on pobrać od użytkownika dane. Dane te to ścieżka do pliku. Następnie program powinien otworzyć plik, wypisać wszystko co się w nim znajduje i tak cały czas. Tzn. jeśli plik zostanie zaktualizowany, to program ma to wypisać. Tutaj funkcja która jest za to odpowiedzialna:
void runTail(const char *filePath){
system("cls");
char *nextLine;
ifstream stream(filePath);
if(!stream.is_open()||!stream.good()) {
SetConsoleTextAttribute(hl,13-1);
cout<<"!Cannot open the file. Completing the program!";
SetConsoleTextAttribute(hl,8-1);
Sleep(3000);
exit(0);
}
SetConsoleTextAttribute(hl,13-1);
cout<<"ESC to exit.\n\n\n";
SetConsoleTextAttribute(hl,16-1);
while(1){
if(!stream.is_open()||!stream.good()) {
SetConsoleTextAttribute(hl,13-1);
cout<<"!Cannot open the file. Completing the program.!";
SetConsoleTextAttribute(hl,8-1);
Sleep(3000);
exit(0);
}
if(kbhit()){
if(getch()==27){SetConsoleTextAttribute(hl,8-1); exit(0);};
}
nextLine="NULL";
stream>>nextLine;
cout<<nextLine<<endl;
}
}
Program sypie się na "cout<<nextLine<<endl;". Oczywiście dodam jeszcze jedną rzecz, mianowicie char *last. Oraz if'a który będzie sprawdzać, czy kolejna linia w pliku równa się last'owi. Jeśli nie to ma ją wczytać, wypisać itd.