title: Send raw data to printer programmatically
body: <p>I want to send to my printer data I load from a file so that it can print a barcode (ITF 2/5).</p>
  
  <p>if I use the command prompt and do "print c:\test lpt1", it works like a charm and it prints the expected barcode. However, when I try to do this programmatically, the printer fails to provide said barcode. Readable text works fine, it's (so far) exclusively an issue I have with the barcode printing.</p>
  
  <p>I have the following code in which ( I thought ) I would be sending a printer raw data (not rendered in any way) so that the printer can decide how to decode those bytes I'm sending to it.</p>
  
  <pre><code>std::FILE* fd = fopen("c:\\test", "rb");
  std::fseek(fd, 0L, SEEK_END);
  int size = std::ftell(fd);
  std::fseek(fd, 0L, SEEK_SET);
  int beginning = std::ftell(fd);
  if(fd == NULL)
  {
      std::cerr &lt;&lt; "Error opening file\n";
      return;
  }
  char* buffer = (char*)malloc(size);
  std::fread(buffer, 1, size, fd);
  std::ofstream output("lpt1", std::ios_base::out);
  output &lt;&lt; buffer;
  </code></pre>
  
  <p>My only guess (and a blind one, at that) is that I am mistakingly assuming the ofstream is receiving raw data when it's not... and I don't know why or how to solve that.</p>
  
  <p>I am not asking for a 'do my homework for me' answer (Although a very clear and epic answer would be awesome) but at least if you could point me in the right way of why I am not getting the expected result, I would be really grateful. Even some keywords for searching and researching on my own would be great, too. I honestly have no idea of what I am doing wrong.</p>
  
  <p>This is some new code I tried because of a suggestion to use IOStreams, again, I get NOT the desired result when I try to edit the content of input.rdbuf().</p>
  
  <pre><code>static void ImprimirArchivo(unsigned char* path)
  {
      std::ifstream input((char*)path, std::ios::binary);
      std::ofstream output("lpt1", std::ios::binary);
  
      std::istreambuf_iterator&lt;char&gt; eos;
      std::istreambuf_iterator&lt;char&gt; streamInputIterator (input.rdbuf());
  
      bool codeBarStarted = false;
      int iterationsCounter = 0;
      while(streamInputIterator!=eos)
      {
          if(*streamInputIterator == 0x14)
          {
              output &lt;&lt; '1d';
              output &lt;&lt; '6b';
              output &lt;&lt; '05';
              output &lt;&lt; '30';
              codeBarStarted = true;
          }
          else
          {
              output &lt;&lt; *streamInputIterator;
          }
  
          if(codeBarStarted)
          {
              iterationsCounter++;
              if(iterationsCounter == 10)
              {
                  output &lt;&lt; 0x00;
                  codeBarStarted = false;
                  iterationsCounter = 0;
              }
          }
  
          streamInputIterator++;
      }
  </code></pre>
  
  <p>Please note that when I do
              if(*streamInputIterator == 0x14)
              {
                  output &lt;&lt; '1d';
                  output &lt;&lt; '6b';
                  output &lt;&lt; '05';
                  codeBarStarted = true;
              }</p>
  
  <p>If I replace that with
              if(*streamInputIterator == 0x14)
              {
                  output &lt;&lt; 0x1d;
                  output &lt;&lt; 0x6b;
                  output &lt;&lt; 0x05;
                  codeBarStarted = true;
              }</p>
  
  <p>the corresponding output is still wrong, but wholly different. When I use 0xXY, what's printed is the decimal number as in: output &lt;&lt; 0x1d makes the printer print "29" (text).</p>