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

Twi*_*ato 1 c++ c++11

所以我熟悉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();
Run Code Online (Sandbox Code Playgroud)

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

0x804b164 the sID is sID-33921
Run Code Online (Sandbox Code Playgroud)

如何将其隐藏或仅生成此内容?如果不是记忆,有人可以告诉我这究竟是什么吗?我还想指出我正在使用G ++,并将build标志设置为C++ 11.

use*_*661 6

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