cpp_prac/demos/file_io_example.cpp
2025-01-11 17:45:38 +01:00

24 lines
506 B
C++

#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
void print_bytes(std::string infile) {
std::ifstream in{infile};
int c;
while ((c = in.get()) != EOF) {
std::cout << "read: " << std::setw(3) << c << " [" << char(c) << "]"
<< std::endl;
}
}
int main(int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " filename" << std::endl;
return 1;
}
print_bytes(argv[1]);
return 0;
}