crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

> Функция Си fread и функция QFile read, нестыковка
AD
  опции профиля:
сообщение 22.12.2008, 14:36
Сообщение #1


Профессионал
*****

Группа: Участник
Сообщений: 2003
Регистрация: 4.2.2008
Из: S-Petersburg
Пользователь №: 84

Спасибо сказали: 70 раз(а)




Репутация:   17  


Ну чтобы лучше понять ошибку вот из MSDN описание fread:
Цитата
Reads data from a stream.

size_t fread( void *buffer, size_t size, size_t count, FILE *stream );

Parameters
buffer - Storage location for data
size - Item size in bytes
count - Maximum number of items to be read
stream - Pointer to FILE structure

Return Values
fread returns the number of full items actually read, which may be less than count if an error occurs or if the end of the file is encountered before reaching count. Use the feof or ferror function to distinguish a read error from an end-of-file condition. If size or count is 0, fread returns 0 and the buffer contents are unchanged.


А вот Qt-шный read():
Цитата
qint64 QIODevice::read ( char * data, qint64 maxSize )
Reads at most maxSize bytes from the device into data, and returns the number of bytes read. If an error occurs, such as when attempting to read from a device opened in WriteOnly mode, this function returns -1.
0 is returned when no more data is available for reading.
See also readData(), readLine(), and write().


Вот как его я использую (Uint = unsigned int)
/// Чтение файла загрузки
    bool LogReader::TRead()
    {
        Uint var = (Uint)1E+6;
        bool bBlock = false, file_read = false;
        vector<LOGRECORD> log;
        time_t before_read, contin_read;        time(&before_read);

        while(fread(&var, sizeof(var), 1, file) > 0 && !feof(file))
        {
            Suint adr = var % 256;
            /// Определение начала/конца одной записи и записывание ее в вектор
        }

        /// Закрываем файл с логом
        Shutdown();    
        return true;
    }


Вот как использую Qt-шный read()

/// Чтение файла загрузки
bool LogReader::tRead()
    {
        char var[4];
        bool bBlock = false, file_read = false;
        vector<LOGRECORD> log;
        time_t before_read, contin_read;        time(&before_read);

        while(_file -> read(var, sizeof(var)) > 1)
        {
            Suint adr = (unsigned int)var % 256;
            /// Определение начала/конца одной записи и записывание ее в вектор
        }

        /// Закрываем файл с логом
        shutdown();
        return true;
    }


Хочу, чтобы код выполнял идентичные действия. Подскажите, пожалуйста, что не так? Как правильно преобразовать значение прочитанное из файла?
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


2 чел. читают эту тему (гостей: 2, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 28.3.2024, 15:05