How can I fix SD.exists() not accepting String.c_str()?
The compiler throws an "invalid conversion from 'const char*' to 'char*' [-fpermissive]" error
Thank you!
How can I fix SD.exists() not accepting String.c_str()?
The compiler throws an "invalid conversion from 'const char*' to 'char*' [-fpermissive]" error
Thank you!
Show Code or what you said doesn't make lots of sense.
The compiler throws an "invalid conversion from 'const char*' to 'char*' [-fpermissive]" error
Use a cast, or ditch the stupid String class altogether.
I think I might do that, converting a String into a null-terminated sequence works until it doesn't, and when it doesn't it's just a pain.
converting a String into a null-terminated sequence works until it doesn't, and when it doesn't it's just a pain.
There are only two reasons why it wouldn't. The first would be that the String is bigger than the array you've tried to "convert" it to. The second would be that there is something wrong with your code.
To be clear, the conversion works. Some of the SD library methods don't seem to take it though, and that's what my problem is.
#include <SPI.h>
#include <SD.h>
String myString;
File myFile;
void setup()
{
myString = "filename.txt";
myFile = SD.open(myString.c_str(), FILE_READ);
if(SD.exists(myString.c_str())){} //this is where the problem is
}
void loop(){}
if(SD.exists(myString.c_str())){} //this is where the problem is
if(SD.exists((char *)myString.c_str())){} //this is where the problem is solved
Thank you sir!