У меня возникла проблема. У меня есть класс ученика, в котором есть атрибуты fname и lname.
Я возвращаю экземпляр ученика из метода findLoser. Я могу напечатать имя fname, но не имя lname. Это не дает никаких ошибок. Я попытался напечатать длину lname из метода получения, и он дал правильный результат, а также я попытался напечатать букву за буквой из lname, используя индексацию, и он печатается, но когда я пытаюсь напечатать все lname, он не печатается.
Под заголовком и остальными файлами
Код: Выделить всё
#ifndef CLIST_HPP
#define CLIST_HPP
#include
using namespace std;
class Student{
private:
string fname;
string lname;
bool seen;
public:
Student(){};
Student(string fname, string lname);
string getLname(){return this->lname;};
string getFname(){return this->fname;};
void setSeen(){seen = !seen;};
bool getSeen(){return seen;};
};
class Cell{
public:
Cell* next;
Cell* prev;
Student* student;
};
class Clist{
public:
friend class Cell;
Clist(){current = nullptr;tracker = nullptr;temp = nullptr; count = 0;}
void print();
Cell* current ;
Cell* tracker;
Cell* temp ;
int count;
Student* findLoser();
void insert(string fname, string lname);
};
# endif
Код: Выделить всё
#include
#include
#include
#include "Clist.hpp"
using namespace std;
Student::Student(string fname, string lname){
this->fname = fname;
this->lname = lname;
this->seen = false;
}
Student* Clist::findLoser(){
tracker = current;
int i = current->student->getLname().length()-1;
while(true){
while(i>0){
tracker = tracker->next;
i--;
}
if(tracker->student->getSeen()){
return tracker->student;
}
else{
tracker->student->setSeen();
}
}
}
void Clist::print(){
tracker = current;
int i =0 ;
while(igetLname() next;
i++;
}
}
void Clist::insert(string fname, string lname){
Student* student = new Student(fname, lname);
Cell* newCell = new Cell();
newCell->student = student;
if(current == nullptr){
current = newCell;
newCell-> next = newCell;
newCell-> prev = newCell;
}
else{
temp = current->prev;
newCell->next = current;
temp->next = newCell;
current-> prev = newCell;
}
count++;
}
bool checkIsFileEmpty(ifstream& pFile)
{
return pFile.peek() == std::ifstream::traits_type::eof();
}
int main(){
ifstream inputFile("late.txt");
if(checkIsFileEmpty(inputFile)){
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78172269/not-able-to-print-one-attribute-while-remaining-are-printing-to-console[/url]
Мобильная версия