manipulators for cout for StateList class

This commit is contained in:
gandc 2024-05-24 18:45:00 +03:00
parent c55592d210
commit 4b454b9f63
Signed by: gandc
GPG Key ID: 9F77B03D43C42CB4

21
pr6.cpp
View File

@ -4,9 +4,24 @@
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
// Манипулятор для вывода в научном формате
template <typename T>
ostream& scientific_format(ostream& os, const T& value) {
os << std::scientific << value;
return os;
}
// Манипулятор для вывода в 8-ричной системе счисления
template <typename T>
ostream& octal_format(ostream& os, const T& value) {
os << std::oct << value;
return os;
}
template<class T>
class Element {
protected:
@ -364,7 +379,7 @@ public:
}
return os;
}
// Overloading the subscript operator
T& operator[](int index) {
if (index < 0 || index >= this->count) {
@ -431,7 +446,9 @@ public:
friend ostream& operator<<(ostream& os, const StateList& stateList) {
Element<State>* current = stateList.stateList.getHead();
while (current != nullptr) {
os << current->getInfo() << endl;
//os << current->getInfo() << endl;
// Выводим элемент в научном виде и в 8-ричной системе счисления
os << scientific << current->getInfo() << " " << oct << current->getInfo() << endl;
current = current->getNext();
}
return os;