I don't think it's the c_str()
making troubles here, but how you're using struct stat
.
You should create a struct stat
instance and pass it's address:
// ...
//iterate through list
map<string,struct stat> fileStats;
for(list<string>::iterator it = files.begin(); it != files.end(); it++){
struct stat entry;
stat(it->c_str(),&entry);
fileStats[*it]=entry;
cout<<entry.st_blocks<<" "<<*it<<endl;
}
What you're doing is letting stat()
write to the address coming from an uninitialized pointer (which will most likely end up in a segfault).
Note that you'll also need to change the map type to get this working.