Twin Potato Twin Potato - 8 months ago 33
C++ Question

C++11 Writing to a file also writes out memory location?

So I'm getting acquainted to C++ and have this problem when writing to a text file it also writes the memory location? here is my source code.

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

std::string studentIDString = std::to_string(studentID);"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;

When I open the text file it generates I get what I assume is memory?

0x804b164 the sID is sID-33921

How would I get this to either be hidden or just not generate this? And if it isn't memory can someone tell me what this actually is? I would also like to point out I'm using G++ with the build flag set to C++11.


You are not supposed to do userprefs << std::cout. It is writing the address of std::cout in the file.