strstream s;
s << "var%05lX" << operand << '\0';

result:
s ==> var%05lXoperand
Thanks
Jack

Re: is this statement correct? by Alex

Alex
Fri Jul 20 02:40:42 CDT 2007

"Jack" <jl@knight.com> wrote:
> strstream s;
> s << "var%05lX" << operand << '\0';
>
> result:
> s ==> var%05lXoperand

As long as it compiles, it is correct. If `operand' by
chance is a string with content "operand", then you'll get
desired result. If you want to output the name of a
variable, then you need to use preprocessor's stringizing
operator #:

#define STRINGIZE(x) #x

strstream s;
s << "var%05lX" << STRINGIZE(operand) << '\0';


Alex


Re: is this statement correct? by Jack

Jack
Fri Jul 20 05:13:38 CDT 2007


"Alex Blekhman" <tkfx.REMOVE@yahoo.com>
???????:OHYHIFqyHHA.464@TK2MSFTNGP02.phx.gbl...
> "Jack" <jl@knight.com> wrote:
>> strstream s;
>> s << "var%05lX" << operand << '\0';
>>
>> result:
>> s ==> var%05lXoperand
>
> As long as it compiles, it is correct. If `operand' by chance is a string
> with content "operand", then you'll get desired result. If you want to
> output the name of a variable, then you need to use preprocessor's
> stringizing operator #:

Whoops.... I actually wanted this
var15... 16 etc
I'd like to sprintf the content of the variable, not the variable name
But this was not what i expected....
Thanks
Jack



>
> #define STRINGIZE(x) #x
>
> strstream s;
> s << "var%05lX" << STRINGIZE(operand) << '\0';
>
>
> Alex
>



Re: is this statement correct? by adebaene

adebaene
Fri Jul 20 06:21:24 CDT 2007

On Jul 20, 12:13 pm, "Jack" <j...@knight.com> wrote:
> "Alex Blekhman" <tkfx.REM...@yahoo.com>
> ???????:OHYHIFqyHHA....@TK2MSFTNGP02.phx.gbl...
>
> > "Jack" <j...@knight.com> wrote:
> >> strstream s;
> >> s << "var%05lX" << operand << '\0';
>
> >> result:
> >> s ==> var%05lXoperand
>
> > As long as it compiles, it is correct. If `operand' by chance is a string
> > with content "operand", then you'll get desired result. If you want to
> > output the name of a variable, then you need to use preprocessor's
> > stringizing operator #:
>
> Whoops.... I actually wanted this
> var15... 16 etc
> I'd like to sprintf the content of the variable, not the variable name
> But this was not what i expected....
> Thanks

#include <iomanip>

s<<"var"<<std::setw(5)<<std::setfill('0')<<std::hex<<operand;

Arnaud
MVP - VC


Re: is this statement correct? by Jack

Jack
Fri Jul 20 07:06:41 CDT 2007


<adebaene@club-internet.fr>
???????:1184930484.038767.260850@57g2000hsv.googlegroups.com...
> On Jul 20, 12:13 pm, "Jack" <j...@knight.com> wrote:
>> "Alex Blekhman" <tkfx.REM...@yahoo.com>
>> ???????:OHYHIFqyHHA....@TK2MSFTNGP02.phx.gbl...
>>
>> > "Jack" <j...@knight.com> wrote:
>> >> strstream s;
>> >> s << "var%05lX" << operand << '\0';
>>
>> >> result:
>> >> s ==> var%05lXoperand
>>
>> > As long as it compiles, it is correct. If `operand' by chance is a
>> > string
>> > with content "operand", then you'll get desired result. If you want to
>> > output the name of a variable, then you need to use preprocessor's
>> > stringizing operator #:
>>
>> Whoops.... I actually wanted this
>> var15... 16 etc
>> I'd like to sprintf the content of the variable, not the variable name
>> But this was not what i expected....
>> Thanks
>
> #include <iomanip>
>
> s<<"var"<<std::setw(5)<<std::setfill('0')<<std::hex<<operand;
Hi arnaud,
Thank you for your kind reply
wow.. quite a long statement :)
but hmmm.... eh..... I really like to use "var%05X", cos it is neater for
maintainence.... :)
are there any possible ways of doing it?
Thanks
Jack



>
> Arnaud
> MVP - VC
>



Re: is this statement correct? by Igor

Igor
Fri Jul 20 07:31:28 CDT 2007

"Jack" <jl@knight.com> wrote in message
news:eaircXsyHHA.1184@TK2MSFTNGP04.phx.gbl
> wow.. quite a long statement :)
> but hmmm.... eh..... I really like to use "var%05X", cos it is neater
> for maintainence.... :)
> are there any possible ways of doing it?

Use sprintf or similar. There are also things like Boost Format library:

http://www.boost.org/libs/format/index.html

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: is this statement correct? by Tim

Tim
Sat Jul 21 23:23:37 CDT 2007

"Jack" <jl@knight.com> wrote:
>
>but hmmm.... eh..... I really like to use "var%05X", cos it is neater for
>maintainence.... :)

"Neater for maintenance"? What do you think that means? I almost always
reach for printf for things like this, but that's because I'm a dinosaur,
and I do it with the full understanding that there are better ways to do it
today.

Please do not fool yourself into thinking that it is "better".
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Re: is this statement correct? by Alexander

Alexander
Mon Jul 23 13:28:38 CDT 2007

There is one way in which this FORTRAN style string formatting
adopted in C is superior to the C++ attempts - it's graphic.
Meaning that most of the time you can actually get a pretty good
idea what the actual output will look like from the format string
alone. I use it exclusively despite its shortcomings as a reservoir
of maintenance bugs.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"Tim Roberts" <timr@probo.com> wrote in message
news:grm5a310c01mbie98hps7qvk9s401r2in2@4ax.com...
> "Jack" <jl@knight.com> wrote:
>>
>>but hmmm.... eh..... I really like to use "var%05X", cos it is neater for
>>maintainence.... :)
>
> "Neater for maintenance"? What do you think that means? I almost always
> reach for printf for things like this, but that's because I'm a dinosaur,
> and I do it with the full understanding that there are better ways to do
> it
> today.
>
> Please do not fool yourself into thinking that it is "better".
> --
> Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.