Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Last active January 17, 2019 04:17
Show Gist options
  • Save ryutorion/9757725 to your computer and use it in GitHub Desktop.
Save ryutorion/9757725 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
/*!
@param[in] path path of a file
@return byte size of a file (return -1 when file cannnot open)
*/
int filesize(char const * path)
{
std::ifstream fin(path, std::ios::in | std::ios::ate);
return fin ? static_cast<int>(fin.tellg()) : -1;
}
int main()
{
std::cout << filesize("filesize.cpp") << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment