[HH] c++ strings?
Jerry Feldman
gaf at blu.org
Thu Dec 13 12:33:49 EST 2012
On 12/13/2012 08:03 AM, Greg London wrote:
> Sorry, this seems like it would be easy, but I'm stumped.
>
> I bring in two integers and a string, and I want to
> create another string that contains the
> integers in hex format and the first string.
>
> It would be one line in perl or verilog.
>
> I can't get it to work at all in C++.
> And every example I've seen so far using stringstream
> seems to require many, many lines of code.
>
>
> void ActualExpected(int actual, int expected, const string &msg){
> stringstream ss;
>
>
> the next line would hopefully be something like this:
>
> ss << "actual=0x" << [actual in string hex format]
> << "expected=0x " << [expected in string hex format]
> << msg;
>
> But for the life of me, I can't get any examples to work.
> And all the examples use several lines of code.
Try this:
ss << "actual=0x" << std::hex << actual << " expected=0x" << std::hex <<
expected << " " << msg;
--
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: 545 bytes
Desc: OpenPGP digital signature
URL: <http://lists.blu.org/pipermail/hardwarehacking/attachments/20121213/c1d688c2/attachment.sig>
More information about the Hardwarehacking
mailing list