Unless I am missing something, looks like you have everything readily available. Total number of extensions is
fileMap.size()
Then you can iterate of this map printing number of files and byte count
for (auto i=fileMap.begin(); i!=fileMap.end(); ++i)
cout << i->first << '=' << i->second.totalFiles << ':' << i->second.fileSize << endl;
Here is the test program that prints totals.
#include <iostream>
#include <map>
class fileStats
{
public:
int totalFiles;
long long fileSize;
fileStats() : totalFiles(0), fileSize(0) {}
fileStats(int f, long long s) : totalFiles(f), fileSize(s) {}
fileStats& operator+=(const fileStats& other)
{
totalFiles += other.totalFiles;
fileSize += other.fileSize;
return *this;
}
};
int main(int argc, char* argv[]) {
typedef std::map< std::string, fileStats > map_type;
map_type fileMap;
fileMap["cpp"].totalFiles++;
fileMap["cpp"].fileSize += 11111;
fileMap["h"].totalFiles++;
fileMap["h"].fileSize += 22222;
fileMap["cpp"].totalFiles++;
fileMap["cpp"].fileSize += 33333;
fileStats totals;
for (map_type::const_iterator i=fileMap.begin(); i!=fileMap.end(); ++i)
totals += i->second;
std::cout << "total files=" << totals.totalFiles << ' ' << "total size=" << totals.fileSize << std::endl;
return 0;
}