Question: Hi i want to save many different csv files from a function with a naming convention based on a different double value. I do this with a for loop and pass a string value to save each .csv file differently. Below is an example of what I'm trying to do the desired result would be 

```
1.1_file.csv
1.2_file.csv

```

but instead i get 

```
1.1_file.csv
1.11.2_file.csv

```

Here is a working sample code, what can i do to fix this

```
#include <sstream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <vector>

int main(){
    std::string file = "_file.csv";
    std::string s;
    std::ostringstream os;
    double x;

    for(int i = 0; i < 10; i++){
        x = 0.1 + 0.1 *i;
        os << std::fixed << std::setprecision(1);
        os << x;
        s = os.str();
        std::cout<<s+file<<std::endl;
        s.clear();
    }

    return 0;
}

```

Answer: 
```
// Sent when addresses are resolved
- (void)netServiceDidResolveAddress:(NSNetService *)netService
{
    // Make sure [netService addresses] contains the
    // necessary connection information
    if ([self addressesComplete:[netService addresses]
                 forServiceType:[netService type]]) {
        [services addObject:netService];
    }
}

// Verifies [netService addresses]
- (BOOL)addressesComplete:(NSArray *)addresses
           forServiceType:(NSString *)serviceType
{

    // Perform appropriate logic to ensure that [netService addresses]
    // contains the appropriate information to connect to the service

    NSData *myData = nil;
    myData = [addresses objectAtIndex:0];

    NSString *addressString;
    int port=0;
    struct sockaddr *addressGeneric;
    struct sockaddr_in addressClient;

    addressGeneric = (struct sockaddr *) [myData bytes];

    switch( addressGeneric->sa_family ) {
        case AF_INET: {
            struct sockaddr_in *ip4;
            char dest[INET_ADDRSTRLEN];
            ip4 = (struct sockaddr_in *) [myData bytes];
            port = ntohs(ip4->sin_port);
            addressString = [NSString stringWithFormat: @"IP4: %s Port: %d", inet_ntop(AF_INET, &ip4->sin_addr, dest, sizeof dest),port];
        }
            break;

        case AF_INET6: {
            struct sockaddr_in6 *ip6;
            char dest[INET6_ADDRSTRLEN];
            ip6 = (struct sockaddr_in6 *) [myData bytes];
            port = ntohs(ip6->sin6_port);
            addressString = [NSString stringWithFormat: @"IP6: %s Port: %d",  inet_ntop(AF_INET6, &ip6->sin6_addr, dest, sizeof dest),port];
        }
            break;
        default:
            addressString=@"Unknown family";
            break;
    }

    NSLog(@"Client Address: %@",addressString);

    return YES;
}

```

This is the output
Client Address: IP4: 192.168.69.38 Port: 58612
I found [a post](http://blog.evandavey.com/2009/07/how-to-convert-nsdata-to-nsstring.html) which suggests the following solution.

```
NSString* addressString = [[NSString alloc] initWithData:addressData encoding:NSASCIIStringEncoding];

```

Though it does **not** output a human readable string for me... It might work for you. 

---

This is what is written to the console when I print the `NSData` object.

```
<10026a5e 0a0a7893 00000000 00000000>

```

Meanwhile, I found out that the **second segment** is the **hexadecimal** form of the ip-address. In this example it is ...

```
10.10.120.147 // 0a0a7893

```

---

I have written a [Host class](https://gist.github.com/3782610) that does the conversion. The `NSString` extension can be found [here](http://forums.macrumors.com/showthread.php?t=977076). I only use the first 16-bytes address and ignore all others. Feel free to extend the class.