Skip to content

Instantly share code, notes, and snippets.

@maidis
Last active January 16, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maidis/24cfcabee13f16da591048b19b728e21 to your computer and use it in GitHub Desktop.
Save maidis/24cfcabee13f16da591048b19b728e21 to your computer and use it in GitHub Desktop.
C++17 ile Dosya Boyutu
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream testFile("test.azw3", ios::binary);
const auto begin = testFile.tellg();
testFile.seekg (0, ios::end);
const auto end = testFile.tellg();
const auto fsize = (end-begin);
cout << fsize << endl; // 38100108
}
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
try {
std::cout << fs::file_size("test.azw3") << std::endl;
} catch(fs::filesystem_error& ex) {
std::cout << ex.what() << '\n';
}
}
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::error_code ec{};
auto size = fs::file_size("test.azw3", ec);
if (ec == std::error_code{})
std::cout << size << '\n';
else
std::cout << "error when accessing test file, size is: "
<< size << " message: " << ec.message() << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment