Twisol pretty much explained it.
Basically, I think you're running into extremely common frustrations with C/C++, namely that you can't just "do things" and have to jump through lots of hoops to do what seem like relatively simple tasks such as getting the output of a process. For example, yes, you can open a pipe to a process, but before you can use that output, you need to read out from the file until EOF, etc.
For all its benefits, C++ is most certainly not a terribly friendly language, and it doesn't make life easy. :-/
Some clarifications/elaborations on what Twisol said:
Quote: 1) I can't initialise variables with functions
You can, it's just that you weren't getting what you thought you were. The return values of the functions were not of the appropriate type. An integer is not an array of characters, for example.
Quote: 2) I can't call a function in the middle of a cout line and expect to get away with it.
You can, but the cout streaming will use the return values, whereas that function doesn't return the hostname -- it sets it into a buffer. (The reason is, basically, that it has to because of how C works -- it's a C library.) So you printed out the return value (which was 0) and the buffer was set, but you didn't print out the buffer. |