Hello, I have several cout statements in my code, that all have to print similar strings.
Example:
Code:
std::cout << "WARNING: corrupt CHARACTER_LIST_REQUEST packet received from: \n"
<< "SystemID: " << sourceSystem << "\n"
<< "IP: " << (net->getSystemAddress(sourceSystem)).ToString(true) << "\n"
<< (dataLength < 8 ? "packet too small" : "packet too large") << std::endl;
The parts where it prints the SystemID and IP are needed in every warning/error message, so I'd like to create a function that does it for me. Ofcourse I could easily write a function that uses cout itself, but I'd like to be able to put it in the cout statement itself.
Like this:
Code:
std::cout << "WARNING: corrupt CHARACTER_LIST_REQUEST packet received from: \n"
<< systemIP(sourceSystem)
<< (dataLength < 8 ? "packet too small" : "packet too large") << std::endl;
I could let systemIP return a char* or std::string, but then I'd have to somehow deal with deallocating them.
How can this be done? I'd like to only have that single function call line in the std::cout.
PS. this isn't a big deal, I'm mainly asking to learn something from it.