title: How to access file data in memory after a block read in C++
body: <p>I am having a very difficult time with this block of code: Ubuntu OS and g++</p>
  
  <pre><code> is.open(name.c_str(),ios::in | std::ifstream::binary); }
  while (!is) ; // this is the end of the user input loop, asking for "name"
  // get length of file:
  is.seekg (0, is.end);
  int length = is.tellg();
  is.seekg (0, is.beg);
  // allocate memory:
  char * buffer = new char [length];
  // read data as a block:
  is.read (buffer,length);
  is.close();
  </code></pre>
  
  <p>This code works and the whole file is properly displayed on my terminal. The problem comes up when I try to do anything else with the file data. I've managed this, starting from the above:</p>
  
  <pre><code>is.close();
  std::cout.write (buffer,length);
  char x;
  int i;
  char *it = buffer;
  char *ip;
  std::cout &lt;&lt; "\nbuffer contains: \n\n";
  ip = it;
  //  for ( i = 0 ; 10  ; ++i ) {
  //  std::cout &lt;&lt; &amp;ip &lt;&lt; "\n";
  //  ip++ ; }
  std::cout &lt;&lt; &amp;ip &lt;&lt; "\n";
  *ip++ ;
  std::cout &lt;&lt; &amp;ip &lt;&lt; "\n";
  *ip++ ;
  std::cout &lt;&lt; &amp;ip &lt;&lt; "\n";
  ip++ ;
  std::cout &lt;&lt; &amp;ip &lt;&lt; "\n";
  std::cout &lt;&lt; "\n";
  </code></pre>
  
  <p>I used this,  cout &lt;&lt; "buffer is: " &lt;&lt; typeid(*buffer).name() &lt;&lt; '\n'; which gave buffer is: c. Also, the for loop is commented out because it doesn't ever quit. The first 8 characters of the file are: (define , including the space) The single statements in the code above give  0x7fffa7119610 repeated 4 times.</p>
  
  <p>I need to search the file data multiple times, character by character. What should I do to make that possible? And if I try memcpy into an array of characters, how do I create the array of the right size?</p>