Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Дописать в файл 10 байтов


Автор: Alca 19.11.2008, 17:31
Дописать в файл 10 байтов, файл уже открыт для записи
Код

FILE *pFile = fopen(sFilePath.c_str(), "rb");
if (NULL == pFile) {
    return false;
}
//чего здесь писать?
fclose(pFile);



Автор: Sartorius 19.11.2008, 17:35
Цитата(Alca @  19.11.2008,  18:31 Найти цитируемый пост)
FILE *pFile = fopen(sFilePath.c_str(), "rb");

где для записи то он открыт?))

fseek(pFile, 0, SEEK_END) сделай


Автор: destrd 19.11.2008, 17:36
Код

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

Автор: Alca 19.11.2008, 17:59
Код

    const std::string csVerifStamp = "0123456789";
    FILE *pFileIn = fopen(sFilePathIn.c_str(), "rb");
    if (NULL == pFileIn) {
        return false;
    }

    fseek(pFileIn, 0, SEEK_END);
    fwrite(csVerifStamp.c_str(), 1, csVerifStamp.size(), pFileIn);
    rewind(pFileIn);

    fclose(pFileIn);

Чета в файл вообще ничего не пишеться.  smile 

Автор: warmonger_ 19.11.2008, 18:12
Цитата

mode
    C string containing a file access modes. It can be:
    "r"    Open a file for reading. The file must exist.
    "w"    Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
    "a"    Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
    "r+"    Open a file for update both reading and writing. The file must exist.
    "w+"    Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
    "a+"    Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.



Автор: Alca 19.11.2008, 18:18
Спасло:
Код

rb+

Автор: vinter 19.11.2008, 18:26
Цитата(Alca @  19.11.2008,  19:18 Найти цитируемый пост)
Спасло:

 smile тебе надо ab

Автор: Alca 19.11.2008, 18:41
Не было времени буквари читать  smile .

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)