-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.cpp
47 lines (36 loc) · 1.24 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <string>
#include <iostream>
#include <iomanip>
#include "PrefixLog.h"
using namespace std;
struct Foo {
Foo(string n) : name(n) {}
string name;
};
ostream &operator<<(ostream& os, const Foo& foo) {
return os << "[\n" // multi-line object output
<< " Foo:'" << foo.name << "'\n"
<< "]";
}
int main()
{
using PrefixLog::Log;
Log("1) Setting Prefix:");
Log("***| ") << "This Log\nadds a prefix\nto every line.";
Log("2) Works like std::cout:");
Log(5) << "It works " // New line
<< "just like std::cout" // Still same line
<< endl // New line
<< "and supports std::endl.";
Log("3) Trailing Newlines:");
Log(5, '-') << " You don't need \\n (or std::endl) as the last character";
Log(5, '+') << " But it handles them in case you forget :)" << endl;
Log("4) Manipulators and Overloads:");
Log(" INFO: ")
<< "It supports manipulators: " << fixed << setprecision(4) << 1.5 << endl
<< "And and objects, even if multi-line:\n" << Foo("bar");
Log("5) Function Fallback:");
Log("- Can be used as standalone function.");
Log("- Unlike prefix mode, the last trailing newline is not ignored!\n");
Log("---");
}