[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
C 字符串格式化
sscanf()用于格式化字符串
与scanf()类似,但scanf()以键盘为输入,但sscanf()以固定字符串为输入源
int sscanf(char *buffer, const char *format, [argument]...); //
format:一个或多个{%[*] [width] [{h | I | I64 | L}]type | ' ' | '\t' | '\n' | 非%符号}
// * 表示跳过此数据不读入,如(%*d、%*s) 遇到整数不读入、遇到字符串不读入 // {a|b|c}
表示a、b、c中选一,[d]表示有没有d都可以 // width 表示读取的宽度 // type 表示%s,%d之类 // %*[width] [{h
| l | I64 | L}]type 表示满足该条件的被过滤掉,不会向目标参数中写入值
sprintf()与snprintf()
将格式化后的数据写入到某个字符串中,snprintf()更安全
int sprintf( char *buffer, const char *format, [argument]...); int
snprintf(char *buffer, size_t size, const char *format, [argument] ...); //
buffer:char型指针,指向将要写入的字符串的缓冲区。 // size: 表示当前buffer的最大容量 // format:格式化字符串。
// [argument]...:可选参数,可以是任何类型的数据。 // 返回值:字符串长度(strlen)
C++ 字符串格式化
stringstream 流
stringstream ss; string a; ss.setf(); // 设置一些属性 ss << setprecision(15) <<
a; // 设置读取的位数,并将a中数据保存到流中 string str; ss >> str; // 将流中数据输出保存到str中 int
num; ss << num; // 将流中数据转化为整型保存在num中 // note: stringstream
解析对象时,是以空格和回车键为分隔符的,若想以其他字符为分隔符,需要使用getline()函数
stringstream 读取多行数据
ifstream fin(path, std::ios::in); // 文件流 while (!fin.eof()) { string
tmp; getline(fin, tmp); // 读取一行放入tmp中 } stringstream ss(str); //
创建内容为str的字符串流 string c; while (getline(ss, c, ',')) { // 从输入流中读取以,分割的字符串并存入c中
cout << c << endl; }