I’m trying to make a loop with a timer so that every 10 seconds the code writes a new text file and names it “log_file_001.txt”, “log_file_002.txt”, etc. I’m having an issue trying to convert an integer to a string
#include
#include “mbed.h”
Timer timer;
int n;
int main()
{
timer.start();
n=1; //set initial value of loop count
while(1) {
if (timer.read_ms()>=10000) {
n=n+1;
timer.reset();
}
FILE *fp=fopen("/sd/mydir/log_file_00" + std::to_string(n) + “.txt”,“w”); //name file, open file to write
}
}