sprintf 将字串格式化。
最近在opencv中使用了for循环连续读入某一个文件夹中的所有图片,所以在cvLoadImage中需要图片名称的参数,如果写成:
IplImage *image=cvLoadImage("c:\\image\\%d.jpg",i);
然后opencv中就会出现image不存在的问题。这时用sprintf函数,将输入直接输入到一个char性的数组中,这样在赋给cvloadiamge函数,就可以正确确定图片的路径。
char img_name[100];
sprintf(img_name,"C:\\testimage\\%d.jpg",m);
IplImage* img = cvLoadImage(img_name,0);
下面是sprintf函数的具体使用:
在头文件 #include<stdio.h>中
语法: int sprintf(string format, mixed [args]...);
返回值: