$cast usage

The $cast system task can be used to assign values to variables that might not ordinarily be valid because of differing data type. $cast can be called as either a task or a function.

The syntax for $cast is as follows:

function int $cast( singular dest_var, singular source_exp );

or

task $cast( singular dest_var, singular source_exp );

The dest_var is the variable to which the assignment is made.
The source_exp is the expression that is to be assigned to the destination variable.

Use of $cast as either a task or a function determines how invalid assignments are handled.
When called as a task, $cast attempts to assign the source expression to the destination variable. If the assignment is invalid, a run-time error occurs, and the destination variable is left unchanged.
When called as a function, $cast attempts to assign the source expression to the destination variable and returns 1 if the cast is legal. If the cast fails, the function does not make the assignment and returns 0. When called as a function, no run-time error occurs, and the destination variable is left unchanged.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <stdio.h> #include <iostream> #include <chrono> #include <thread> #include <DjiRtspImageSource.h> #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" static inline int64_t now() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); } static int write_data_to_file(const char* name, uint8_t* data, int size) { FILE* fd = fopen(name, "wb"); if(fd) { int w = (int)fwrite(data, 1, size, fd); fclose(fd); return w; } else { return -1; } } char rtsp_url = "rtsp://192.168.42.142:8554/live"; int main(int argc, char** argv) { if(argc < 1) return -1; if(argc == 1) { std::cout << "Usage : " << argv[0] << " <url>" << std::endl; return -1; } int64_t ts = now(); DjiRtspImageSource service(rtsp_url); service.setImageCallback(nullptr, [&ts](void* handler, uint8_t* frmdata, int frmsize, int width, int height, int pixfmt) -> void { printf("Image %d@%p -- %dx%d -- %d\n", frmsize, frmdata, width, height, pixfmt); if(frmdata) { int64_t t = now(); if(t - ts > 1000) { ts = t; char name[64]; static int counter = 0; sprintf(name, "pictures/%dx%d-%d_%d.jpg", width, height, pixfmt, ++counter); if(pixfmt == 5) stbi_write_jpg(name, width, height, 3, frmdata, 80); } } }); service.start(); for(;;) //for(int i=0; i<30; i++) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } service.stop(); std::cout << "done." << std::endl; return 0; } 利用上述代码实现提取并解码二维码的信息,并将解码结果保存到tta文件夹下保存为文件名为 list_of_goods,给出c++源码
07-16

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值