1
- #define RAPIDJSON_HAS_STDSTRING 1
2
1
#include " rapidjson/document.h"
2
+ #include " rapidjson/filewritestream.h"
3
3
#include < rapidjson/prettywriter.h>
4
- #include < rapidjson/stringbuffer.h>
5
4
6
5
#include < algorithm>
7
6
#include < iostream>
8
7
9
8
using namespace rapidjson ;
10
9
using namespace std ;
11
10
12
- void printIt (Document &doc)
11
+ void printIt (const Value &doc)
13
12
{
14
- string output ;
15
- StringBuffer buffer ;
16
- PrettyWriter<StringBuffer > writer (buffer );
13
+ char writeBuffer[ 65536 ] ;
14
+ FileWriteStream os (stdout, writeBuffer, sizeof (writeBuffer)) ;
15
+ PrettyWriter<FileWriteStream > writer (os );
17
16
doc.Accept (writer);
18
17
19
- output = buffer.GetString ();
20
- cout << output << endl;
18
+ cout << endl;
21
19
}
22
20
23
- struct ValueNameComparator
21
+ struct NameComparator
24
22
{
25
23
bool
26
24
operator ()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
27
25
const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const
28
26
{
29
- string lhss = string (lhs.name .GetString ());
30
- string rhss = string (rhs.name .GetString ());
31
- return lhss < rhss;
27
+ return (strcmp (lhs.name .GetString (), rhs.name .GetString ()) < 0 );
32
28
}
33
29
};
34
30
@@ -55,7 +51,7 @@ int main()
55
51
}
56
52
**/
57
53
58
- std::sort (d.MemberBegin (), d.MemberEnd (), ValueNameComparator ());
54
+ std::sort (d.MemberBegin (), d.MemberEnd (), NameComparator ());
59
55
60
56
printIt (d);
61
57
/* *
0 commit comments