於是我就用這樣的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