Skip to content

Instantly share code, notes, and snippets.

@udaya1223
Last active Oct 5, 2016
Embed
What would you like to do?
Formatting a file name using user input.
#include <sstream>
#define IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_PREFIX "left_"
#define RIGHT_PREFIX "right_"
#define IMG_NUM_PAD (4)
#define IMG_EXTENSION "bmp"
#define START_FRAME_NUM (1)
#define END_FRAME_NUM (10)
using namespace std;
string ZeroPadNumber(int num, int pad){
stringstream ss;
// The number is converted to string with the help of stringstream
ss << num;
string ret;
ss >> ret;
if(pad < 1){
return ret;
}else{
// Append zero chars
int str_length = ret.length();
for (int i = 0; i < pad - str_length; i++)
ret = "0" + ret;
return ret;
}
}
int main(void){
char szFilePath[512];
for(int i=START_FRAME_NUM; i<=END_FRAME_NUM; i++) {
sprintf(szFilePath, "%s/%s%s.%s", LEFT_IMAGE_FILE_PATH, LEFT_PREFIX, ZeroPadNumber(i, IMG_NUM_PAD).c_str(), IMG_EXTENSION);
printf("%s\n", szFilePath);
sprintf(szFilePath, "%s/%s%s.%s", RIGHT_IMAGE_FILE_PATH, RIGHT_PREFIX, ZeroPadNumber(i, IMG_NUM_PAD).c_str(), IMG_EXTENSION);
printf("%s\n", szFilePath);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment