ファイルシステムコールの使用

ファイルシステムコールの使用

ファイルを開く、書き込み、閉じるためのシステムコールを学習しようとしています。この例を使用しましたが、結果は次のとおりです。

gcc: error trying to exec 'cc1plus': execvp: No such file or directory

これは私のプログラムです:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int main (int argc, char *argv[])
{
    int fd1;
    char buf[128];
    fd1 = open("Desktop/this.txt", O_WRONLY);
    if (fd1 == -1) {
        perror("File cannot be opened");
        return EXIT_FAILURE;
    }

    /* Enter the data to be written into the file */
    scanf("%127s", buf);

    write(fd1, buf, strlen(buf)); /* fd1 is the file descriptor, buf is the character array used to
 hold the data, strlen(buf) informs the function that the number of bytes equal to the length of the
 string in the buffer need to be copied */

    close(fdl);

    return 0;
}

ベストアンサー1

私はあなたがUbuntu、Debian、またはいくつかの派生製品を使用していると仮定します。システムが最新であることを確認し、g++ をインストールしてください。

おすすめ記事