于是我就用这样的Log class:日志记录,如何获得命令结束?
#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;
我希望它能够得到它是oune日志消息和a << "here's one with a number: " << 5;
是另一个。
crently它输出一条消息:
1:here's a message;
2:
;
3:here's one with a number: ;
4:5;
我想保持其sintax(的<<
无限数量的,大范围的值类型,没有(
和)
在API周围),但使它输出:
1:here's a message
;
2:here's one with a number: 5;
如何做这种事?
+1这就是聪明! –
确定性破坏是德Epix的WinRAR的™ – Puppy
@DeadMG:要点是让它可以分割不'一个文本line'消息,但'一个代码行messages'因此,例如'一个<<的std :: ENDL << STD: :endl << std :: endl << std :: endl;'将是一条消息。 – Rella