char img1_file[] = "D:\\project\\pic\\d.jpg";
char img2_file[] = "D:\\project\\pic\\d.jpg";
这样,我获得的是制定路径下的文件名。有一堆照片,分别以001.jpg 002.jpg 003.jpg ……排列
我每次只对顺序相连的两幅jpg进行处理。请问文件名那我该怎么定义呢?能让 img1_file[]得到001.jpg,
img2_file[] 得到002.jpg 。处理完后,img1_file[]自动得到003.jpg ,img2_file[]自动得到004.jpg。
以此类推。有没有什么好的方法,或者直接函数。
char img2_file[] = "D:\\project\\pic\\d.jpg";
这样,我获得的是制定路径下的文件名。有一堆照片,分别以001.jpg 002.jpg 003.jpg ……排列
我每次只对顺序相连的两幅jpg进行处理。请问文件名那我该怎么定义呢?能让 img1_file[]得到001.jpg,
img2_file[] 得到002.jpg 。处理完后,img1_file[]自动得到003.jpg ,img2_file[]自动得到004.jpg。
以此类推。有没有什么好的方法,或者直接函数。
sprintf(img1_file[0],"D:\\project\\pic\\00%d.jpg" ,x)
if(x<100)
sprintf(img1_file[0],"D:\\project\\pic\\0%d.jpg" ,x)
if(x<1000)
sprintf(img1_file[0],"D:\\project\\pic\\%d.jpg" ,x)
sprintf(img1_file[0],"D:\\project\\pic\\00%d.jpg" ,x)
if(x>=10&&x<100)
sprintf(img1_file[0],"D:\\project\\pic\\0%d.jpg" ,x)
if(x>=100&&x<1000)
sprintf(img1_file[0],"D:\\project\\pic\\%d.jpg" ,x)
CString strFile2;
CString strFile2;
while(int i = 0; i<xxxx; i++)
{
strFile1.Format("%s%3d.jpg", strPath, 2*i+1);
strFile2.Format("%s%3d.jpg", strPath, 2*i+2);
}CString 是很好用的东西
%s%3d.jpg 编译错误,而且我用的是OPENCV,定义的时候是CHAR类型的文件名。怎么更改呢?
CString strPath = "D:\\project\\pic\\";
strFile1.Format("%s%3d.jpg", strPath, 2*i+1);
改成
CString strPath = _T("D:\\project\\pic\\");
strFile1.Format(_T("%s%3d.jpg"), strPath, 2*i+1);
用了unicode的话,CString就是宽字符的,而opencv不是。那就老老实实的用运行时库里的函数吧
size_t wcstombs( char *mbstr, const wchar_t *wcstr, size_t count );
char szPath[MAX_PATH] = "D:\\project\\pic\\";
char szFile1[MAX_PATH];
char szFile2[MAX_PATH];
while(int i = 0; i<xxxx; i++)
{
sprintf_s(szFile1, "%s%3d.jpg", strPath, 2*i+1);
sprintf_s(szFile2, "%s%3d.jpg", strPath, 2*i+2);
}
还有sprintf_s的具体参数看下msdn最近用while用得有点多。
error C2665: 'sprintf_s' : none of the 2 overloads could convert all the argument types
这么几行代码,这么多错误,无语。。
char szPath[MAX_PATH] = "D:\\project\\pic\\";
char strFile1[MAX_PATH];
char strFile2[MAX_PATH];
for( int j = 1; j<2; j++)
{
sprintf_s(strFile1,MAX_PATH, _T("%s%30d.jpg"), szPath, 2*j+1);
sprintf_s(strFile2,MAX_PATH, _T("%s%30d.jpg"), szPath, 2*j+2);
}error C2665: 'sprintf_s' : none of the 2 overloads could convert all the argument types
#define MAX_COUNT 1000char img1_file[MAX_PATH] = {0};
char img2_file[MAX_PATH] = {0};
for(int i=0; i != MAX_COUNT; i+=2)
{
sprintf_s(img1_file, sizeof(img1_file), "D:\\project\\pic\\%03d.jpg"),i);
sprintf_s(img2_file, sizeof(img2_file), "D:\\project\\pic\\%03d.jpg"),i+1);
}
不要用_T了
sprintf_s接受的是char*
你定义了Unicode _T之后是wchar_t*
error C2665: 'sprintf_s' : none of the 2 overloads could convert all the argument types
#include "stdio.h"void main()
{
char szPath[MAX_PATH] = "D:\\project\\pic\\";
char szFile1[MAX_PATH];
char szFile2[MAX_PATH];
for(int i = 0; i<2; i++)
{
sprintf_s(szFile1, MAX_PATH, "%s%03d.jpg", szPath, 2*i+1);
sprintf_s(szFile2, MAX_PATH, "%s%03d.jpg", szPath, 2*i+2);
printf(szFile1);
printf(szFile2);
}
}
结果:
D:\project\pic\001.jpgD:\project\pic\002.jpgD:\project\pic\003.jpgD:\project\pic
\004.jpg请按任意键继续. . .
error C2665: 'sprintf_s' : none of the 2 overloads could convert all the argument types
我这显示还是。error C2665: 'sprintf_s' : none of the 2 overloads could convert all the argument types
真的不好意思,麻烦大哥了。
sprintf_s(szFile1, MAX_PATH, "%s%03d.jpg", szPath, 2*i+1);
sprintf_s(szFile2, MAX_PATH, "%s%03d.jpg", szPath, 2*i+2);