Skip to content

Commit ecd2cc3

Browse files
committed
modify some compile error.
1 parent 1e59b29 commit ecd2cc3

File tree

5 files changed

+31
-57
lines changed

5 files changed

+31
-57
lines changed

example/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ set(EXAMPLES
1111
add_definitions(-D_GLIBCXX_USE_CXX11_ABI)
1212
set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS})
1313

14-
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
14+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
1515
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive -g -fjsoncpp")
1616
else()
1717
add_definitions(-D_SCL_SECURE_NO_WARNINGS
18-
D_CRT_SECURE_NO_WARNINGS
19-
-D_WIN32_WINNT=0x601
20-
-D_WINSOCK_DEPRECATED_NO_WARNINGS)
18+
D_CRT_SECURE_NO_WARNINGS
19+
-D_WIN32_WINNT=0x601
20+
-D_WINSOCK_DEPRECATED_NO_WARNINGS)
2121
endif()
2222

2323
foreach (example ${EXAMPLES})
+5-10
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1-
#incldue <iostream>
2-
#incldue <ifstresm>
3-
#incldue <sstream>
1+
#include <fstream>
42
#include <json/json.h>
53
/*
64
parse from stream,collect comments and capture error info.
75
86
>g++ readFromStream.cpp -ljsoncpp -std=c++11 -o readFromStream
97
>./readFromStream
10-
118
// comment head
129
{
1310
// comment before
1411
"key" : "value"
1512
}
1613
// comment after
1714
// comment tail
18-
1915
*/
20-
21-
using namespace std;
22-
int main(int argc,char* argv[]){
16+
int main(int argc,char* argv[]) {
2317
Json::Value jsonRoot;
2418
Json::Value jsonItem;
19+
std::ifstream ifs;
2520
ifs.open(argv[1]);
2621
jsonRoot.clear();
2722

2823
Json::CharReaderBuilder builder;
2924
builder["collectComments"]=true;
3025
JSONCPP_STRING errs;
3126
if(!parseFromStream(builder,ifs,&jsonRoot,&errs)){
32-
cout << errs <<endl;
27+
//std::cout << errs <<std::endl;
3328
return -1;
3429
}
35-
cout << jsonRoot <<endl;
30+
//std::cout << jsonRoot <<std::endl;
3631
return 0;
3732
}
+10-17
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
1-
#incldue <iostream>
2-
#incldue <ifstresm>
3-
#incldue <memory>
41
#include <json/json.h>
52
/*
63
parse a string to Value object with CharReaderBuilder class or Reader class
74
>g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString
85
>./readFromString
9-
106
colin
117
20
12-
138
*/
14-
using namespace std;
15-
int main(){
16-
string strRes = "{\"Age\": 20, \"Name\": \"colin\"}";
9+
int main() {
10+
std::string strRes = "{\"Age\": 20, \"Name\": \"colin\"}";
1711
int nLen = (int)strRes.length();
18-
const char *pStart = strRes.c_str();
12+
const char *pStart = strRes.c_str();
1913

20-
std::string err;
14+
JSONCPP_STRING errs;
2115
Json::Value root;
2216

2317
#if 0 //old way
2418
Json::Reader myreader;
2519
myreader.parse(strRes,root);
2620
#else // new way
2721
Json::CharReaderBuilder jsonreader;
28-
std::unique_ptr<Json::CharReader> const reader(jsonreader.newCharReader());
22+
Json::CharReader* reader(jsonreader.newCharReader());
2923
if(!reader.parse(pStart,pStart+nLen,&root,&err)){
30-
cout << "error" << endl;
24+
//std::cout << "error" << std::endl;
3125
return -1;
3226
}
3327
#endif
34-
35-
string strName = root["Name"].asString();
28+
std::string strName = root["Name"].asString();
3629
int Age = root["Age"].asInt();
3730

38-
cout << strName << endl;
39-
cout << strAge << endl;
40-
31+
//std::cout << strName << std::endl;
32+
//std::cout << strAge << std::endl;
33+
delete reader;
4134
return 0;
4235
}

example/streamWrite/streamWrite.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
#incldue <iostream>
2-
#incldue <sstream>
3-
#incldue <memory>
1+
#include <sstream>
42
#include <json/json.h>
53
/*
64
write the Value object to stream
75
>g++ streamWrite.cpp -ljsoncpp -std=c++11 -o streamWrite
86
>./streamWrite
9-
107
{
118
"Age" : 20,
129
"Name" : "robin"
1310
}
14-
1511
*/
16-
using namesp std ;
17-
int main(){
18-
string strRes = " ";
12+
int main() {
13+
std::string strRes = " ";
1914
Json::Value root ;
2015
Json::StreamWriterBuilder jsonbuilder;
21-
std::unque_ptr<Json::StreamWriter> writer(jsonbuilder.newStreamWriter());
22-
ostringstream os;
16+
Json::StreamWriter* writer(jsonbuilder.newStreamWriter());
17+
std::ostringstream os;
2318

2419
root["Name"] = "robin";
2520
root["Age"] = 20;
2621
writer->write(root,&os);
2722
strRes = os.str();
2823

29-
cout << strRes <<endl;
30-
24+
//std::cout << strRes <<std::endl;
25+
delete writer;
3126
return 0;
3227
}

example/stringWrite/stringWrite.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
#incldue <iostream>
2-
#incldue <sstream>
31
#include <json/json.h>
42
/*
53
write a Value object to a string
64
>g++ stringWrite.cpp -ljsoncpp -std=c++11 -o stringWrite
75
>./stringWrite
8-
96
{
107
"action" : "run",
118
"data" :
129
{
1310
"number" : 11
1411
}
1512
}
16-
1713
*/
18-
19-
using namespace std ;
20-
int main(){
14+
int main() {
2115

2216
Json::Value root ;
2317
Json::Value t_data;
@@ -28,14 +22,11 @@ int main(){
2822

2923
#if 0 // old way
3024
Json::FastWriter writer;
31-
string json_file = writer.write(root);
25+
std::string json_file = writer.write(root);
3226
#else // new way
3327
Json::StreamWriterBuilder builder;
34-
string json_file = Json::writeString(builder,root);
28+
std::string json_file = Json::writeString(builder,root);
3529
#endif
36-
37-
cout<< json_file << endl;
38-
39-
return 0;
40-
30+
//std::cout<< json_file << std::endl;
31+
return 0;
4132
}

0 commit comments

Comments
 (0)