Skip to content

Instantly share code, notes, and snippets.

@typelogic
Created March 13, 2020 09:19
Show Gist options
  • Save typelogic/d5ae6069e1d226f99af5725bd485242a to your computer and use it in GitHub Desktop.
Save typelogic/d5ae6069e1d226f99af5725bd485242a to your computer and use it in GitHub Desktop.
c++ streams
#include <iostream>
#include <istream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string filename = "text.txt";
ios::openmode mode = /* ifstream::in;*/ ios::binary;
ifstream fin;
fin.open(filename/*, mode*/);
/*
char c = fin.get();
while (fin.good()) {
std::cout << c;
c = fin.get();
}
*/
char output[100];
if (fin.is_open()) {
while (!fin.eof()) {
//std::cout << fin;
std::cout << fin.readsome << std::endl << std::flush;
fin >> output;
//std::cout << "*\n";
for(int i=0; i<10; ++i) {
std::cout << std::hex << (int)output[i] << std::flush;
}
std::cout << std::endl << std::flush;
}
fin.close();
} else {
std::cout << "cannot open file\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment