链接FlameKm/MultiCommand-flamekm: 多命令 (github.com)
使用方法如下
MultiCommand comm;
void dst(uint8_t id, char *s) {
std::cout << (int)id << " " << s <<std::endl;
}
int main() {
comm.add("msg1", 1, dst);
comm.add("msg2", 2, dst);
comm.add("msg3", 3, dst);
comm.add("msg4", 4, dst);
comm.search((char*)"msg15");
comm.search((char*)"msg26");
comm.search((char*)"msg37");
comm.search((char*)"msg48");
}
结果
1 5
2 6
3 7
4 8
直接导入头文件可用,注意,单片机C++可用,如果需要c的话可以自行更改。