O
O
OKNOZA2016-03-11 11:22:46
C++ / C#
OKNOZA, 2016-03-11 11:22:46

Why doesn't it add a line to the end of the file?

I’m not strong in C ++, I took a script on prastors, redid it a little, compiled everything without errors, only one works, it doesn’t insert a line at the end of the file, it displays an error, how to fix it? I think that you need permission to write 0777? How to do?

#include <iostream>                                   // для оператора cout
#include <cstdio>                                     // для функции rename
#include <sys/stat.h>
#include <fstream>
 
int main ()
{
    char oldfilename[] = "/tmp/hls/test";                   // старое имя файла
    char newfilename[] = "/tmp/hls/20160308165800";                   // новое имя файла
 
    if ( rename( oldfilename, newfilename ) == 0 )
    {
        std::cout << "Файл успешно переименован /n";
    } 
    else
    {    
        std::cout << "Ошибка переименования файла /n";
    }
    mkdir("/tmp/hls/test",0777);
   
    std::ofstream ifs("/tmp/hls/20160308165800/live.m3u8", std::ios_base::in | std::ios_base::app);
    if (ifs.is_open())
    {
        ifs << "\n#EXT-X-ENDLIST";
        ifs.close();
    }
    else
    {
        std::cout << "Error opening file\n";  
    }

    return 0;

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iv_k, 2016-03-11
@iv_k

std::ios_base::in what does it say?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question