0
iが使用JSON形式でシリアル経由ベクトル
マイコード:
...
#include <algorithm>
#include <vector>
#include <sstream>
#include "json.hpp"
using namespace std;
using json = nlohmann::json;
int main(int argc, char *argv[])
{
// read a JSON file
std::stringstream ss;
std::ifstream i("filee.json");
json j_complete = json::parse(i);
std::vector <int> data_send_to_LED;
for (int i =0; i<j_complete["tablica"].size(); i++){
data_send_to_LED.push_back(j_complete["tablica"][i].get<int>());
}
for (int i =0; i<data_send_to_LED.size(); i++){
cout <<"data send: "<< data_send_to_LED[i]<<endl;
}
json j_vec(data_send_to_LED);
int* pv = &data_send_to_LED[0];
...
n = write(sockfd,pv, data_send_to_LED.size());
}
どのように私は、シリアル経由JSONとしてdata_send_to_LEDベクトルを送ることができますか? (あなたがする必要があるかもしれません何
json j_vec(data_send_to_LED); // this makes the json text?
int* pv = &data_send_to_LED[0]; // hope you don't do anything with data_send_to_LED after this point.
...
n = write(sockfd,pv, data_send_to_LED.size()); // this sends the data as binary
をあなたのコードのすべての詳細を知らなくても
私はこのようなものを追加します。json j_vec(data_send_to_LED); auto pv = j_vec.get_ptr();それでも私はポインタを取得できません。エラー "Bad address"が表示されますか? –
kolo