views:

166

answers:

1

There doesn't seem to be a standard constructor so I've taken to doing the following

void myMethod(char delimiter = ',')
{
    string delimiterString = 'x';
    delimiterString[0] = delimiter;
    // use string version ...
}

Is there a better way to do this?

+16  A: 

std::string has a constructor that will do it for you:

std::string delimiterString(1, delimiter);

The 1 is a size_t and denotes the number of repetitions of the char argument.

Meredith L. Patterson
bdonlan
*facepalm* You're right. I'm awake too late again.
Meredith L. Patterson
sth
bdonlan
Wow, I am totally full of fail tonight. In my defence I prefer references to anything involving pointers or the address-of operator, but that was a real newbie mistake on my part. The iterator constructor example is hilariously overwritten, though.
Meredith L. Patterson