1、整数和字符串补零
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <sstream>
#include <opencv2/opencv.hpp>
int main()
{
std::string index_str="48";
int index1=233;
std::string aa,bb;
stringstream ss;
ss << setw(5) << setfill('0') << index_str;
ss >> aa;
std::cout << aa << std::endl;
ss.clear();
ss << setw(6) << setfill('0') << index1;
ss >> bb;
std::cout << bb << std::endl;
cv::imwrite(img_path + "_" + aa + "_" + bb + ".jpg", dst);
return 0;
}
输入数值:
index_str: 48
index1: 233
输出结果:
00048
000233