gpt4 book ai didi

C++11 写入文件也会写出内存位置?

转载 作者:行者123 更新时间:2023-11-30 00:46:07 27 4
gpt4 key购买 nike

所以我开始熟悉 C++ 并且在写入文本文件时遇到这个问题它也会写入内存位置?这是我的源代码。

  std::ofstream userprefs;
srand(time(0));
int studentID = rand() % (99999 - 4 * 55) + 5 / 2;

std::string studentIDString = std::to_string(studentID);
userprefs.open("studentInformation.txt", std::ofstream::out | std::ofstream::app);

std::cout << "The Student ID is sID-"+ studentIDString +" (Copy everything including the sID.\nyou can also find this in the studentInformation.txt file.)"<< std::endl;

userprefs << std::cout << "the sID is sID-"+ studentIDString << std::endl;
userprefs.close();

当我打开它生成的文本文件时,我得到的是内存?

0x804b164 the sID is sID-33921

我如何才能隐藏它或不生成它?如果不是内存,有人能告诉我这到底是什么吗?我还想指出,我使用的是 G++,构建标志设置为 C++11。

最佳答案

你不应该做 userprefs << std::cout .它正在写std::cout的地址在文件中。

关于C++11 写入文件也会写出内存位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607394/

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