Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created May 11, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaityo256/c3f69663e6d1f0322d48bebbc31430ab to your computer and use it in GitHub Desktop.
Save kaityo256/c3f69663e6d1f0322d48bebbc31430ab to your computer and use it in GitHub Desktop.
連番ファイル名を作る方法
#include <cstdio>
#include <cstdlib>
#include <string>
void save_data(const std::string filename) {
printf("%s\n", filename.c_str());
}
int main() {
std::string filename;
for (int i = 0; i < 100; i++) {
char buf[256];
std::snprintf(buf, sizeof(buf), "data%03d.dat", i);
filename = buf;
save_data(filename);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment