Last active
January 16, 2019 13:36
-
-
Save maidis/24cfcabee13f16da591048b19b728e21 to your computer and use it in GitHub Desktop.
C++17 ile Dosya Boyutu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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