I have following code:
#include <stdio.h> // For printf()
#include <sys/stat.h> // For struct stat and stat()
struct stat stResult;
if(stat("Filename.txt", &stResult) == 0)
{
// We have File Attributes
// stResult.st_size is the size in bytes (I believe)
// It also contains some other information you can lookup if you feel like it
printf("Filesize: %i", stResult.st_size);
}
else
{
// We couldn't open the file
printf("Couldn't get file attributes...");
}
Now. How can I pass my own string through stat()? Like this
string myStr = "MyFile.txt";
stat(myStr, &stResult)
If you are talking about a C++ std::string, you might want to use
string myStr = "MyFile.txt";
stat(myStr.c_str(), &stResult)
so use the c_str() member-function of your string object in order to get a C string representation.
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