Поэтому я использую такой Класс журнала :
#include <stdio.h>
#include <iostream>
class Log
{
public:
int i;
Log()
{
i = 0;
}
template <class T>
Log &operator<<(const T &v)
{
i++;
std::cout << i << ":" << v << ";" <<std::endl;
return *this;
}
Log &operator<<(std::ostream&(*f)(std::ostream&))
{
i++;
std::cout << i << ":" << *f << ";" <<std::endl;
return *this;
}
~Log()
{
std::cout << " [end of message]" << std::endl;
}
};
Который я использую как:
#include <log.h>
int main()
{
Log a;
a << "here's a message" << std::endl;
a << "here's one with a number: " << 5;
std::cin.get();
}
Я хочу, чтобы мой класс журнала получался, когда я кладу ";»Это означает, что если у меня есть a << "here's a message" << std::endl;
, я хочу, чтобы он был в состоянии получить, что это наше лог-сообщение, а a << "here's one with a number: " << 5;
- другое.
постоянно выдает следующее сообщение:
1:here's a message;
2:
;
3:here's one with a number: ;
4:5;
Iхотите сохранить его синтаксис (неограниченное количество <<
, большой диапазон типов значений, нет (
и )
в api), но выведите его:
1:here's a message
;
2:here's one with a number: 5;
Как это сделать