C++ 程序只打印固定的随机 numbers/letters 到 output.txt 文件

C++ program only prints fixed random numbers/letters to the output.txt file

这是我的代码,我是 C++ 的新手,每当我向 output.txt 文件输出任何内容时,无论我尝试输出什么 Screenshot here,我都只会得到随机的 numbers/letters

现在这个问题直到我昨晚尝试复制一个字符串时才出现,但那时当我打印初始字符串时它会正常打印(只要我没有在其他任何地方复制字符串)但是今天早上我醒来时,文件的每一个输出看起来都是随机的 numbers/letters,尽管它们是固定的,所以我假设它们是十六进制或其他东西,有人可以帮我吗。

更新:output.txt从来没有关闭过,我只是关闭并打开它,一切都恢复正常了。

让我们将“hello world”打印为字符和数字(十六进制格式):

#include <string>
#include <iostream>

int main()
{
    std::string bla = "hello world";
    for (auto c : bla)
        std::cout << c << ' ' << std::hex << +c << '\n';
}

输出:

h 68
e 65
l 6c
l 6c
o 6f
  20
w 77
o 6f
r 72
l 6c
d 64

更多阅读:Wikipedia and easier to read table