New here, thought I'd start off with something easy.
Ok I have this function that converts an (int) into a 4 octect IP address, storing each octet of the IP into an array. To output this as a normal IP address, I have to add the dots between each number. The code goes as thus ( all you really need to note is the cout statement at the bottom )-
So the output looks something like 192.24.159.1, just as an example.Code:int i = 0; int n = 24; IP octet[4]; //unsigned int for ( i = 0 ; i < 4 ; i++) { octet[i] = ( ( address >> n ) & 255 ); n -=8; } cout << octet[0] << "." << octet[1] << "." << octet[2] << "." << octet[3];
My question is, I am going to output this in a list with multiple lines, and will be outputting items after this on the same line. So I need to set width to 16 and align this IP to the left, then output the rest of the line uniformly. However, I am unsure how to do this, since the setw() function only grabs the next item on the output stream ( in this case, octet[0] ), and the rest will be pushed a dozen or so spaces over. I need to find a way to make it so this entire bit of code ( the cout statement of this function, basically ) is aligned to the left of a 16-space spot. Not sure if this would involve changing my output, but I'm up for any suggestions.
Sorry if this description is not adequate, I can sure repost if necessary. Thanks for any help.![]()



LinkBack URL
About LinkBacks



