How could I convert the following C code into a C++ equivalent? I have no
idea how to do the formatting in C++.
void OutputPay(Employee *emp){
printf(“%06X %8.3f\n”,emp->DID, emp->DPay);
emp->DPaid = TRUE;
}
Thanks in advance,
Evan 8 1381
EvanB wrote: How could I convert the following C code into a C++ equivalent? I have no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(“%06X %8.3f\n”,emp->DID, emp->DPay); emp->DPaid = TRUE; }
RTFM on "iostream manipulators". Pay attention to 'hex' format flag,
'setfill' manipulator, 'setw' manipulator, 'fixed' format flag, and
'setprecision' manipulator.
V
"EvanB" <ed******@ucdavis.edu> wrote in message
news:78******************************@localhost.ta lkaboutprogramming.com... How could I convert the following C code into a C++ equivalent?
Your code qualifies as "C++ code".
I have no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(“%06X %8.3f\n”,emp->DID, emp->DPay); emp->DPaid = TRUE; }
C++ introduces 'IOStreams', 'stream manipulators',
'stream format flags', etc.:
void OutputPay(Employee *emp)
{
std::cout << std::hex
<< std::setfill('0')
<< std::setw(6}
<< emp->DID
<< std::dec
<< std::fixed
<< std::setprecision(3)
<< std::setw(11)
<< emp-DPay);
emp->DPaid = true; /* 'true' is a C++ keyword */
}
See the declarations of the <ios> and <iomanip> headers.
Recommended books: http://www.josuttis.com/libbook/ http://www.langer.camelot.de/iostreams.html
-Mike
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:al*****************@newsread1.news.pas.earthl ink.net...
I left out one item: void OutputPay(Employee *emp) { std::cout << std::hex << std::setfill('0') << std::setw(6} << emp->DID << std::dec
<< std::setfill(' ')
<< std::fixed << std::setprecision(3) << std::setw(11) << emp-DPay);
emp->DPaid = true; /* 'true' is a C++ keyword */ }
(All formatting changes applied to a stream remain in effect
until specifically changed again -- except 'setw()', which
must be invoked each time a field width need be specified).
-Mike
EvanB wrote: How could I convert the following C code into a C++ equivalent? I have no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(“%06X %8.3f\n”,emp->DID, emp->DPay); emp->DPaid = TRUE; }
Thanks in advance, Evan
void Employee::OutputPay(){
std::cout << boost::format(“%06X %8.3f\n”) % DID % DPay;
DPaid = true;
}
and variations
--
Regards,
Slava
"Vyacheslav Kononenko" <vy********@NOkononenkoSPAM.net> wrote in message
news:Fx*****************@mencken.net.nih.gov... EvanB wrote:
How could I convert the following C code into a C++ equivalent? I have no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(%06X %8.3f\n,emp->DID, emp->DPay); emp->DPaid = TRUE; }
Thanks in advance, Evan
void Employee::OutputPay(){ std::cout << boost::format(%06X %8.3f\n) % DID % DPay; DPaid = true; }
and variations
-- Regards, Slava
Technically speaking, that's not standard C++, is it? Isn't the Boost
library third-party software? (I don't see anything related to Boost in my
libraries, at least.)
Also, isn't that a typo? I think you meant to use the << operators before
DID and DPay, right?
-Howard
Howard posted: "Vyacheslav Kononenko" <vy********@NOkononenkoSPAM.net> wrote in message news:Fx*****************@mencken.net.nih.gov... EvanB wrote:
How could I convert the following C code into a C++ equivalent? I have no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(%06X %8.3f\n,emp->DID, emp->DPay); emp->DPaid = TRUE; }
Thanks in advance, Evan
void Employee::OutputPay(){ std::cout << boost::format(%06X %8.3f\n) % DID % DPay; DPaid = true; }
and variations
-- Regards, Slava
Technically speaking, that's not standard C++, is it? Isn't the Boost library third-party software? (I don't see anything related to Boost in my libraries, at least.)
Also, isn't that a typo? I think you meant to use the << operators before DID and DPay, right?
-Howard
Then copy-paste the boost file. Now it's Standard C++!
( or would that be piracy? ;-P )
-JKop
Awesome, thanks. That helps tremendously :) The spacing operations were
throwing me off in C++.
Evan
"Howard" <al*****@hotmail.com> wrote in message
news:0a*********************@bgtnsc04-news.ops.worldnet.att.net... "Vyacheslav Kononenko" <vy********@NOkononenkoSPAM.net> wrote in message news:Fx*****************@mencken.net.nih.gov... EvanB wrote:
How could I convert the following C code into a C++ equivalent? I have
no idea how to do the formatting in C++.
void OutputPay(Employee *emp){ printf(%06X %8.3f\n,emp->DID, emp->DPay); emp->DPaid = TRUE; }
Thanks in advance, Evan
void Employee::OutputPay(){ std::cout << boost::format(%06X %8.3f\n) % DID % DPay; DPaid = true; }
and variations
-- Regards, Slava
Technically speaking, that's not standard C++, is it? Isn't the Boost library third-party software? (I don't see anything related to Boost in
my libraries, at least.)
Well, to be fair, the OP didn't ask for a solution that only used the
standard library. The boost library is a good library that one can download
from boost.org, so I think it deserves to be mentioned.
Also, isn't that a typo? I think you meant to use the << operators before DID and DPay, right?
No, boost::format overloads the % operator. See http://www.boost.org/libs/format/doc/format.html
--
David Hilsee This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yensao |
last post by:
Hi,
I have a hard time to understand difference and similarities between
Relational database model and the Object-Oriented model. Can somebody
help me with this?
Thank you in advance.
...
|
by: b83503104 |
last post by:
Hi,
Can someone tell me the difference between single quote and double
quote?
Thanks
|
by: Frank |
last post by:
For my website i would like to display the age of my son in years,
months, days and hours.
For now i manage to get a result for totals. Like the total number of
days.
This is the beginning:
...
|
by: Rich |
last post by:
I was considering C# for developing a scientific application, but I have
noticed a ~30% difference between VC++ .NET and C# on the same machine,
under identical conditions:
double a = 0,b = 0, c...
|
by: jamesyreid |
last post by:
Hi,
I'm really sorry to post this as I know it must have been asked
countless times before, but I can't find an answer anywhere.
Does anyone have a snippet of JavaScript code I could borrow...
|
by: bbawa1 |
last post by:
Hi,
I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.
In first column i have to show the data from field ItemsReceived and
in second...
|
by: Petronius |
last post by:
Hallo, does anyone have an idea how to implement difference lists in
Javascript?
Thanks allot in advance
|
by: Julius |
last post by:
Hej dudes,
I need to calc the difference between two timestamps / dates ...
For example what i need to calculate:
Date 1: 2007.11.06 - 20:13:04
Date 2: 2007.11.07 - 21:13:04
Difference:...
|
by: viki1967 |
last post by:
Hi all!
This new forum its great! :)
Congratulations !!!
My answer: why this my code not working?
Nothing error but not work the difference.... :
<html>
|
by: cmb3587 |
last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays
Ex:
arrayA: 3 5 8 9
arrayB: 3 4 6 9
difference of A-B: 5 8
however, my...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |