[HH] c++ strings?

Jerry Feldman gaf at blu.org
Tue Nov 20 13:13:22 EST 2012


On 11/20/2012 01:02 PM, Matthew Gillen wrote:
> On 11/20/2012 12:41 PM, Greg London wrote:
>> In perl, it might look like this:
>>
>> sub upper_subroutine{
>>    my ($string)=@_;
>>    lower_subroutine("prefix".$string."postfix".timestamp());
>> }
>>
>> Could someone give me an example of how to do this in C++ so that
>> it looks as close to this perl code as possible?
>
> This will be useful to you for getting the timestamp aspect:
>  http://www.tutorialspoint.com/cplusplus/cpp_date_time.htm
>
> Other than that, use the '+' operator to concatenate C++ string
> objects, much like you use the '.' operator in perl.
>
> Note that you can run into issues if neither of the operands to '+'
> are actual std::string objects (e.g. "foo" + "bar" doesn't work in C++
> like it would in perl, since the literal string is not automatically
> promoted to std::string in some cases).
>
>> If this could happen without anyone having to die, that would
>> be even better.
>
> That's asking a lot ;-)
>
std::string("foo") + std::string("bar") yields the std::string "foobar :-)

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90 
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 543 bytes
Desc: OpenPGP digital signature
URL: <http://lists.blu.org/pipermail/hardwarehacking/attachments/20121120/5005b87b/attachment.sig>


More information about the Hardwarehacking mailing list