C++, Как читать в объектах с данным смещением?

Похоже, что Chrome 24 теперь поддерживает сенсорные события, вероятно, для Windows 8. Поэтому код, размещенный здесь, больше не работает. Вместо того, чтобы пытаться определить, поддерживается ли касание браузером, я теперь связываю события касания и щелчка и проверяю, вызывается ли только одно:

myCustomBind = function(controlName, callback) {

  $(controlName).bind('touchend click', function(e) {
    e.stopPropagation();
    e.preventDefault();

    callback.call();
  });
};

И затем вызываю его:

myCustomBind('#mnuRealtime', function () { ... });

Надеюсь, это поможет!

7
задан shevron 26 June 2009 в 13:41
поделиться

3 ответа

Используйте метод seek :

ifstream strm;
strm.open ( ... );
strm.seekg (x);
strm.read (buffer, y);
11
ответ дан 6 December 2019 в 12:53
поделиться

Вы должны использовать fseek (), чтобы изменить вашу «текущую позицию» в файле на желаемое смещение. Итак, если "f" - ваша переменная FILE *, а смещение - это смещение, то вот как должен выглядеть вызов (по модулю моей утечки памяти):

fseek(f, offset, SEEK_SET);
3
ответ дан 6 December 2019 в 12:53
поделиться

Besides the usual seek-and-read techniques mentioned above, you can also map the file into your process space using something like mmap() and access the data directly.

For example, given the following data file "foo.dat":

one two three

The following code will print all text after the first four bytes using an mmap() based approach:

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <iostream>

int main()
{
  int result = -1;

  int const fd = open("foo.dat", O_RDONLY);
  struct stat s;

  if (fd != -1 && fstat(fd, &s) == 0)
  {
    void * const addr = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
    if (addr != MAP_FAILED)
    {
       char const * const text = static_cast<char *>(addr);

       // Print all text after the first 4 bytes.
       std::cout << text + 4 << std::endl;
       munmap(addr, s.st_size);
       result = 0;
    }

    close(fd);
  }

  return result;
}

You can even use this approach to write directly to a file (remember to msync() if necessary).

Libraries like Boost and ACE provide nice C++ encapsulations for mmap() (and the equivalent Windows function).

This approach is probably overkill for small files, but it can be huge win for large files. As usual, profile your code to determine which approach is best.

2
ответ дан 6 December 2019 в 12:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: