Read and display binary data : istrstream « File Stream « C++ Tutorial






#include <iostream>
#include <strstream>
using namespace std;

int main()
{
  char *p = "this is a test\1\2\3\4\5\6\7";

  istrstream ins(p);

  char ch;

  
  while (!ins.eof()) {
    ins.get(ch);
    cout << hex << (int) ch << ' ';
 
 }
  return 0;
}
74 68 69 73 20 69 73 20 61 20 74 65 73 74 1 2 3 4 5 6 7 7 "








12.17.istrstream
12.17.1.Attempt to read from empty stream
12.17.2.Demonstrating input from an istringstream object
12.17.3.Use istrstream to read int, float and char
12.17.4.How to read the contents of any array that contains text
12.17.5.Read and display binary data