forked from PhysicsX/ExampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
46 lines (35 loc) · 1.03 KB
/
test.cpp
File metadata and controls
46 lines (35 loc) · 1.03 KB
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
45
46
#include <iostream>
#include <string>
#include <vector>
#include "test.pb.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/text_format.h"
using ::google::protobuf::RepeatedField;
using ::google::protobuf::int64;
int main()
{
Test test;
test.add_id(10);
test.add_id(20);
test.add_id(30);
std::cout<<test.id_size()<<std::endl;
std::cout<<test.id(1)<<std::endl;
const RepeatedField<int64>& id_vec = test.id();
for(auto a : id_vec)
{
// *itr += 1000; // this will throw an compiler error. It is not mutable.
std::cout<< "id: "<<a<<std::endl;
}
std::string str;
google::protobuf::TextFormat::PrintToString(test, &str);
std::cout<< str << std::endl;
RepeatedField<int64>* mut_vec = test.mutable_id();
for(auto itr = mut_vec->begin(); itr != mut_vec->end(); ++itr)
{
*itr += 1000; // this will throw an compiler error. It is not mutable.
std::cout<< "id: "<<*itr<<std::endl;
}
std::string str2;
google::protobuf::TextFormat::PrintToString(test, &str2);
std::cout<< str2 << std::endl;
}