|
Next: Startup items
|
| Author |
Message |
External

Since: Mar 21, 2008 Posts: 4
|
(Msg. 1) Posted: Sat Mar 22, 2008 2:00 am
Post subject: One more C++ cout question Archived from groups: comp>sys>mac>programmer>help (more info?)
|
|
|
|
| I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
it possible to get this output using std::cout?
Thanks
|
|
|
| Back to top |
|
 |  |
External

Since: Jun 06, 2005 Posts: 660
|
(Msg. 2) Posted: Sat Mar 22, 2008 5:06 am
Post subject: Re: One more C++ cout question [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <qcneb5-7m7.ln1 DeleteThis @Hedley.internal.thethurmans.com>,
Can I Get a Word In <lorenzo DeleteThis @diespammerhurmans.com> wrote:
> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> it possible to get this output using std::cout?
> Thanks
#include <iostream>
using namespace std;
int main(int argc, const char* argv[])
{
cout << "0x";
cout.flags(ios::hex);
cout.width(  ;
cout.fill('0');
cout << 0x14000 << "\n";
return 0;
} |
|
| Back to top |
|
 |  |
External

Since: Jul 21, 2005 Posts: 150
|
(Msg. 3) Posted: Sat Mar 22, 2008 3:28 pm
Post subject: Re: One more C++ cout question [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <uce-7F9183.05065022032008.DeleteThis@comcast.dca.giganews.com>,
Gregory Weston <uce.DeleteThis@splook.com> wrote:
> In article <qcneb5-7m7.ln1.DeleteThis@Hedley.internal.thethurmans.com>,
> Can I Get a Word In <lorenzo.DeleteThis@diespammerhurmans.com> wrote:
>
> > I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> > it possible to get this output using std::cout?
> > Thanks
>
> #include <iostream>
> using namespace std;
> int main(int argc, const char* argv[])
> {
> cout << "0x";
> cout.flags(ios::hex);
> cout.width( ;
> cout.fill('0');
> cout << 0x14000 << "\n";
> return 0;
> }
That works, but I prefer to use io manipulators:
#include <iostream>
#include <iomanip>
using std::cout;
using std::setw;
using std::setfill;
using std::ios;
using std::hex;
using std::dec;
int main(int argc, char * const argv[]) {
cout << " 0x" << setw(  << setfill('0') << hex << 0x14000 << "\n" << dec << 123 << "\n";
return 0;
} |
|
| Back to top |
|
 |  |
External

Since: Jun 06, 2005 Posts: 660
|
(Msg. 4) Posted: Sat Mar 22, 2008 3:28 pm
Post subject: Re: One more C++ cout question [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <oster-7139AB.08280222032008.RemoveThis@newsclstr02.news.prodigy.com>,
David Phillip Oster <oster.RemoveThis@ieee.org> wrote:
> In article <uce-7F9183.05065022032008.RemoveThis@comcast.dca.giganews.com>,
> Gregory Weston <uce.RemoveThis@splook.com> wrote:
>
> > In article <qcneb5-7m7.ln1.RemoveThis@Hedley.internal.thethurmans.com>,
> > Can I Get a Word In <lorenzo.RemoveThis@diespammerhurmans.com> wrote:
> >
> > > I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> > > it possible to get this output using std::cout?
> > > Thanks
> >
> > #include <iostream>
> > using namespace std;
> > int main(int argc, const char* argv[])
> > {
> > cout << "0x";
> > cout.flags(ios::hex);
> > cout.width( ;
> > cout.fill('0');
> > cout << 0x14000 << "\n";
> > return 0;
> > }
>
> That works, but I prefer to use io manipulators:
>
> #include <iostream>
> #include <iomanip>
> using std::cout;
> using std::setw;
> using std::setfill;
> using std::ios;
> using std::hex;
> using std::dec;
>
> int main(int argc, char * const argv[]) {
>
> cout << " 0x" << setw( << setfill('0') << hex << 0x14000 << "\n" << dec
> << 123 << "\n";
>
> return 0;
> }
Certainly a more elegant solution, but I figured the question was basic
enough that it kind of warranted the most explicit/obvious possible
answer. I've found manipulators confuse people completely new to the
language more than they help right up front. |
|
| Back to top |
|
 |  |
External

Since: Mar 21, 2008 Posts: 4
|
(Msg. 5) Posted: Sun Mar 23, 2008 6:04 pm
Post subject: Re: One more C++ cout question [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gregory Weston wrote:
> In article <oster-7139AB.08280222032008.RemoveThis@newsclstr02.news.prodigy.com>,
> David Phillip Oster <oster.RemoveThis@ieee.org> wrote:
>
>> In article <uce-7F9183.05065022032008.RemoveThis@comcast.dca.giganews.com>,
>> Gregory Weston <uce.RemoveThis@splook.com> wrote:
>>
>>> In article <qcneb5-7m7.ln1.RemoveThis@Hedley.internal.thethurmans.com>,
>>> Can I Get a Word In <lorenzo.RemoveThis@diespammerhurmans.com> wrote:
>>>
>>>> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
>>>> it possible to get this output using std::cout?
>>>> Thanks
>>> #include <iostream>
>>> using namespace std;
>>> int main(int argc, const char* argv[])
>>> {
>>> cout << "0x";
>>> cout.flags(ios::hex);
>>> cout.width( ;
>>> cout.fill('0');
>>> cout << 0x14000 << "\n";
>>> return 0;
>>> }
>> That works, but I prefer to use io manipulators:
>>
>> #include <iostream>
>> #include <iomanip>
>> using std::cout;
>> using std::setw;
>> using std::setfill;
>> using std::ios;
>> using std::hex;
>> using std::dec;
>>
>> int main(int argc, char * const argv[]) {
>>
>> cout << " 0x" << setw( << setfill('0') << hex << 0x14000 << "\n" << dec
>> << 123 << "\n";
>>
>> return 0;
>> }
>
> Certainly a more elegant solution, but I figured the question was basic
> enough that it kind of warranted the most explicit/obvious possible
> answer. I've found manipulators confuse people completely new to the
> language more than they help right up front.
Thanks for the reply. I'm actually comfortable using manipulators, it
just wasn't immediately obvious how to use them to get the output I wanted. |
|
| Back to top |
|
 |  |
External

Since: Mar 21, 2008 Posts: 4
|
(Msg. 6) Posted: Sun Mar 23, 2008 6:05 pm
Post subject: Re: One more C++ cout question [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
David Phillip Oster wrote:
> In article <uce-7F9183.05065022032008.TakeThisOut@comcast.dca.giganews.com>,
> Gregory Weston <uce.TakeThisOut@splook.com> wrote:
>
>> In article <qcneb5-7m7.ln1.TakeThisOut@Hedley.internal.thethurmans.com>,
>> Can I Get a Word In <lorenzo.TakeThisOut@diespammerhurmans.com> wrote:
>>
>>> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
>>> it possible to get this output using std::cout?
>>> Thanks
>> #include <iostream>
>> using namespace std;
>> int main(int argc, const char* argv[])
>> {
>> cout << "0x";
>> cout.flags(ios::hex);
>> cout.width( ;
>> cout.fill('0');
>> cout << 0x14000 << "\n";
>> return 0;
>> }
>
> That works, but I prefer to use io manipulators:
>
> #include <iostream>
> #include <iomanip>
> using std::cout;
> using std::setw;
> using std::setfill;
> using std::ios;
> using std::hex;
> using std::dec;
>
> int main(int argc, char * const argv[]) {
>
> cout << " 0x" << setw( << setfill('0') << hex << 0x14000 << "\n" << dec << 123 << "\n";
>
> return 0;
> }
Thanks, I got it. |
|
| Back to top |
|
 |  |
| Related Topics: | Question about NSTabView - HI I don't know if Gorm/Interface Builder questions are on topic in here, the FAQ doesn't seem to say. Anyway, I had an application working fine with its NSTableView (the delegate was my AppController class). I used Interface Builder to create a..
MTCoreAudio question - Hi, I'm using MTCoreAudio and need to record x seconds (say 5 seconds) of audio into one buffer. I've got the sammple rate but how do I calculate the buffer size? One of the examples I found uses:- // about 25 seconds of recording time #define..
stringWithContentsOfFile question - Using stringWithContentsOfFile I can load an NSString with the contents of a file (obviously). What are the practical limits with regard to the size of file that could be handled? Jim -- Find me at http://www.ursaMinorBeta.co.uk My lucky star is..
Novice question about NSButton - Hello, I have been working my way through developing my first Cocoa app, (a calculator, naturally) and have hit a bit of a wall toward the end. Apologies in advance for the long post. The problem: All my keys are straight NSButtons with a key..
simple assembler question - Hello. My name is Robert and after a long time beeing out of work I am glad to introduce myself. I have 4 years experience as a commercial software developer. I began with the SE/30 and OS 6. Having had a break of 5 years I am back on the Mac Platform.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|