gpt4 book ai didi

c++ - 从文件中读取十六进制数

转载 作者:行者123 更新时间:2023-11-28 08:18:30 25 4
gpt4 key购买 nike

这让我很烦恼,因为我应该能够做到这一点,但是当我读入十六进制数字并将其分配给一个无符号整数时,当我打印出来时,我得到了一个不同的数字。任何建议都会很棒。谢谢

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
fstream myfile;
myfile.open("test.text");
unsigned int tester;
string test;
myfile >> hex >> tester;
cout << tester;
system("pause");
return 0;
}

最佳答案

我打赌你不会得到“不同的数字”。

我打赌你会得到相同的值,但以十进制表示。

您已经在提取十六进制表示值 ( myfile >> hex >> tester );现在也插入一个 ( cout << hex << tester )!

关于c++ - 从文件中读取十六进制数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6776213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com