I am trying to open up a file that I calculate the name into a string. However, it is just giving me compile errors as shown.
for(int i=1;;i++)
{
   String temp = "data";
   temp.concat(i);
   temp.concat(".csv");
   if(!SD.exists(temp))//no matching function for call to sdclass::exists(String&)
   {
      datur = SD.open(temp,FILE_WRITE);
   }
}
I am a java person, so I don't see why this isn't working. I tried a few string object methods but none seem to have worked. I am a bit new at arduino programming but I understand java much better. The point of this for loop is to make a new file each time the arduino reboots.
SD.open expects a character array instead of a String, you need to convert it using the toCharArray method first. Try
  char filename[temp.length()+1];
  temp.toCharArray(filename, sizeof(filename));
  if(!SD.exists(filename)) { 
   ...
  }
Completed Code:
for(int i=1;;i++)
{
   String temp = "data";
   temp.concat(i);
   temp.concat(".csv");
   char filename[temp.length()+1];
   temp.toCharArray(filename, sizeof(filename));
   if(!SD.exists(filename))
   {
      datur = SD.open(filename,FILE_WRITE);
      break;
   }
}
You will find a number of functions take char arrays instead of strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With