且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在循环中保存具有不同名称的图像文件(.jpg)?

更新时间:2023-11-09 14:40:34

循环看起来没问题,但看不到其他代码。



一个错误是文件名需要LPCSTR这是一个C风格的字符串,所以转换你需要的C ++字符串

the loop looks OK, but can't see other code.

one mistake is the filename needs LPCSTR which is a C style string so to convert the C++ string you'd need
str.c_str()





第二个错误是串联+使用字符串而不是C字符串。

所以一个想法是适应方法:





second mistake is concatenation with + works with string but not C strings.
so one idea is to adapt method:

string IntToStr(int n) 
{
    stringstream result;
    result<< "C://webcontent/QR"<<n<<".jpg";
    return result.str();
}





然后将字符串转换为



then convert string to

LPCSTR 


您的问题是关于构建LPCSTR。



尝试以下



Your question is really about constructing a LPCSTR.

Try the following

#include<string>
using namespace std;







for(int n = 0; n < 20; n++)
{
        string filename = "C://webcontent/QR"+ to_string((_ULonglong)n) +".jpg";
        eCode = BCSaveImageA(pBC, filename.c_str(), 4, LBarcodeWidth,LBarcodeHieght, dpi, dpi);
}





如果您的编译器符合C ++ 11标准,则不需要_ULonglong强制转换。



If your compiler is C++11 compliant you wont need the _ULonglong cast.