File size: Difference between revisions
Content added Content deleted
Line 437: | Line 437: | ||
<< std::ifstream("/input.txt", std::ios::binary | std::ios::ate).tellg() << "\n"; |
<< std::ifstream("/input.txt", std::ios::binary | std::ios::ate).tellg() << "\n"; |
||
}</lang> |
}</lang> |
||
===C++ 17=== |
|||
<lang cpp>#include <filesystem> |
|||
#include <iostream> |
|||
void print_file_size(const char* filename) { |
|||
try { |
|||
auto size = std::filesystem::file_size(filename); |
|||
std::cout << "Size of file " << filename << " is " << size << " bytes.\n"; |
|||
} catch (const std::exception& ex) { |
|||
std::cerr << ex.what() << '\n'; |
|||
} |
|||
} |
|||
int main() { |
|||
print_file_size("input.txt"); |
|||
print_file_size("/input.txt"); |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Size of file input.txt is 506 bytes. |
|||
filesystem error: in file_size: No such file or directory [/input.txt] |
|||
</pre> |
|||
=={{header|Clean}}== |
=={{header|Clean}}== |