terryching 最近的时间轴更新
terryching

terryching

V2EX 第 418046 号会员,加入于 2019-06-03 08:55:45 +08:00
terryching 最近回复了
48 天前
回复了 wisefree 创建的主题 C++ C++ 如果通过解析字符串定义一个结构体
看看 GPT4 给出的答案:
运行时解析:使用已有的数据结构,如 std::map 或自定义的数据结构,来在运行时模拟结构体。基于解析得到的信息(字段名、类型、数组大小等),你可以动态地存储和访问数据。这种方法牺牲了类型安全和编译时优化,但提供了灵活性。
```c++
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <typeinfo>
#include <cstdint>

class DynamicStruct {
public:
std::map<std::string, std::vector<uint8_t>> fields;

void addInt(const std::string& name, int value) {
auto data = reinterpret_cast<uint8_t*>(&value);
fields[name] = std::vector<uint8_t>(data, data + sizeof(value));
}

void addDouble(const std::string& name, double value) {
auto data = reinterpret_cast<uint8_t*>(&value);
fields[name] = std::vector<uint8_t>(data, data + sizeof(value));
}

int getInt(const std::string& name) {
if(fields.find(name) != fields.end()) {
auto& data = fields[name];
return *reinterpret_cast<const int*>(data.data());
}
return 0; // Or throw an exception
}

double getDouble(const std::string& name) {
if(fields.find(name) != fields.end()) {
auto& data = fields[name];
return *reinterpret_cast<const double*>(data.data());
}
return 0.0; // Or throw an exception
}

// Similar methods can be added for other types and arrays
};

int main() {
DynamicStruct myStruct;
myStruct.addInt("x", 123);
myStruct.addDouble("y", 456.789);
// For arrays, you might add them element by element or as a block if you know the size

std::cout << "x = " << myStruct.getInt("x") << std::endl;
std::cout << "y = " << myStruct.getDouble("y") << std::endl;

// Accessing array elements would require additional methods

return 0;
}
```
250 天前
回复了 undertow 创建的主题 程序员 工作一天一般写多少行代码
如果有工作需要一天大部分时间敲代码,有两种可能:1. 复杂度低的重复性代码; 2. 任务分配太多导致工作量大。无论哪种,都可以考虑跑路了
2021-08-20 10:34:27 +08:00
回复了 TOUJOURSER 创建的主题 职场话题 坐在我旁边的同事一直抖腿
直接说就行了,不要想太多
2021-01-22 07:57:19 +08:00
回复了 wohenfuyou 创建的主题 C++ 关于 protobuf proto 类型映射到 c++类型
string *是内部使用的,你用接口获取和设置都是 string
2021-01-11 07:54:22 +08:00
回复了 Brentwans 创建的主题 问与答 程序员专职投资可行性
你自己都说了是万万没想到了,说明投资收益和理财能力无关。我觉得可以给自己定几个目标,看看是不是都能达到,大概可以检验一下自己吧。
休息一段时间可以,没必要专职搞吧。
2020-05-09 12:27:19 +08:00
回复了 deepmindlab 创建的主题 互联网 快看,百度首页的 ui 升级了
现在默认用 bing,辅助 Google,百度真的用不上了
@iamvx 被分享的设备设置开启分享的手机作为代理
2020-04-26 07:24:54 +08:00
回复了 ybw 创建的主题 程序员 有没有类似"给 C++程序员的 Python 教程"的东西
有编程基础的随便看看就会了,基础语法内容不多
目测并不是要找“架构师”,而是做过相关项目的有实际经验的全栈工程师,估计已有的都是应届生或者经验不足的,坑太深。
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3233 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 12:16 · PVG 20:16 · LAX 05:16 · JFK 08:16
Developed with CodeLauncher
♥ Do have faith in what you're doing.