返回顶部

c++常用第三方库

json 

nlohmann的一个json.hpp 

https://github.com/nlohmann/json

#include "nlohmann/json.hpp"
using nlohmannJson = nlohmann::json;




int main()
{
            nlohmannJson j;
            j["msgType"] = "clearAll";

            std::string msg = "<lxrobot>" + j.dump();


            nlohmannJson j = {
                {"msgId", msgId},
                {"msgType","GenerateObj"},
                {"ObjType","robot"},
                {"Name",robotName},
                {"Pose",
                    {
                        {"Pos",{{"x",0},{"y",0},{"y",0}}},
                        {"Euler",{{"x",90},{"y",0},{"y",0}}}
                    }
                },
                {"scale",
                    {
                        {"x",1},
                        {"y",1},
                        {"z",1},
                    }
                }
            };

            std::string msg = "<lxrobot>" + j.dump();


}

下面的例子的JSON格式如下:

<lxrobot>{
    "msgId": 13,
    "msgType": "GenerateObj",
    "ObjType": "robot",
    // 对于机器人要加上
    "Name":"abbIRB4600_40_255",
    //"Name":"abbIRB6700_150_320",
    //"Name":"abbIRB660",
    "Pose": {
        "Pos": {
            "x": 0,
            "y": 0,
            "z": 0
        },
        "Euler": {
            "x": 90,
            "y": 0,
            "z": 0
        }
    },
    "scale": {
        "x": 1,
        "y": 1,
        "z": 1
    }
}

 

random 

effolkronium的一个random.hpp

https://github.com/effolkronium/random

#include "effolkronium/random.hpp"
using Random = effolkronium::random_static;

int main()
{
    for (int i = 0; i < 5; i++)  
    {
        int size = Random::get(100, 300);
                std::cout << "size "<<size<<std::endl;
        }

    return 0;  
}        

 

posted @ 2021-12-12 18:05  Zcb0812  阅读(279)  评论(0)    收藏  举报