Linux 文件显示^@

Linux 文件显示^@

这也是我写程序的时候偶然发现的, 然后自己就写了一个小的测试程序看看这个^@到底是什么:

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

using namespace std;

int main() {
        int fd = open("test.txt", O_CREAT | O_RDWR, 0777);
        const char* str = "hello";
        write(fd, str, strlen(str) + 1);
        close(fd);
        return 0;
}

然后我们vim打开test.txt, 显示如下:

hello^@

其实这个^@就是'\0', 我们都知道ASCII码中有很多不可见字符, Linux为了区分这些不可见字符故又将其作了一次编码

猜你喜欢

转载自blog.csdn.net/weixin_43891775/article/details/112428153