c/c 小例子
铲灰
平凡的一个人
展开
-
C++ Json::Value 依次获取Json中的元素值
jsHttp = { "headers" : { "1111" : "111", "2222" : "222", "3333" : "333" }} ///Json::Value 依次获取jsSrc中的每个元素 const Json::Value jsSrc = jsHttp["headers"]; Json::Value::Members member = jsSrc.getMemberNames(); Json...原创 2021-03-17 16:58:54 · 5922 阅读 · 0 评论 -
C++用ifstream读取文件内容
#include <iostream>#include <fstream>using namespace std;void read_file(const std::string &path, std::string &out){ ///std::ifstream fs(path.c_str(), std::ios_base::binary); std::ifstream fs(path, std::ios_base::binary);...原创 2021-01-03 13:55:00 · 3023 阅读 · 0 评论 -
将整数转换成十六进制字符串
#include <string>#include <iostream>using namespace std;std::string from_i_to_hex(size_t n) { const char *charset = "0123456789abcdef"; std::string ret; do { ret = charset[n & 15] + ret; n >&...原创 2021-01-03 13:42:59 · 2258 阅读 · 2 评论 -
把十六进制字符串转换成整数
#include <iostream>#include <string>#include <stdio.h>using namespace std;bool is_hex(char c, int &v){ if (0x20 <= c && isdigit(c)) { v = c - '0'; return true; } else if ('A' <= ...原创 2021-01-03 13:38:07 · 1265 阅读 · 0 评论 -
C语言读写锁
#include <stdio.h>#include <pthread.h>int counter;pthread_rwlock_t rwlock;//3个线程不定时写同一全局资源,5个线程不定时读同一全局资源void *th_write(void *arg){ int t; while (1) { ///互斥量 ...原创 2020-03-16 18:47:31 · 2874 阅读 · 0 评论 -
C++实现回调函数
#include <iostream>#include <string>#include <map>#include <string.h>using namespace std;class Test{public: Test() { m_map.insert(std::pair<string, C...原创 2020-03-04 14:41:46 · 376 阅读 · 0 评论 -
wait/waitpid函数详解
#include<sys/types.h>#include<sys/wait.h>pid_t wait(int *status);pid_t waitpid(pid_t pid, int *status, int options);特殊参数和返回情况:参数pid: >0 回收指定ID的子进程 -1 回收任意子进程(相当于wait...原创 2020-02-26 11:06:17 · 1358 阅读 · 0 评论 -
用fcntl改变File Status Flag
#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <stdlib.h>#define MSG_TRY "try again\n"int main(){ char buf[10] = {0}; ...原创 2020-02-26 10:06:55 · 149 阅读 · 0 评论 -
select函数实现非阻塞读数据
#include <iostream>#include <map>#include <string.h>#include <unistd.h>#include <assert.h>#include <queue>#include <sys/types.h>#include <sys/stat.h...原创 2019-12-26 15:31:43 · 537 阅读 · 1 评论 -
C++类中函数指针的用法
#include <iostream>#include <string>#include <map>#include <vector>using namespace std;class A{public: typedef void (A::*PROC)(int a1, int a2);///这里的PROC是void ()(in...原创 2019-11-01 11:19:58 · 425 阅读 · 0 评论