<tv****@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Below is my code:
#include <string>
#include <iostream>
#include <iomanip>
int main (void){
using namespace std;
string name1 = "JOHN";
int id1 = 1234;
float balance1 = 27000.00;
float available1 = 14000.00;
cout
<<left<<setw(20)<<"NAME"<<setw(20)<<"ID"<<setw(20) <<"BALANCE"<<setw(20)<<"AVAILABLE"<<endl;
cout
<<left<<setw(20)<<name1<<setw(20)<<id1<<setw(20)<< setprecision(15)<<balance1<<setw(20)<<available1<< endl;
}
output:
NAME ID BALANCE AVAILABLE
JOHN 1234 27000 14000
however, I would like to have the output as follow:
NAME ID BALANCE AVAILABLE
JOHN 1234 27000.00Cents 14000.00Cents
Thanks in advance for any hints.
stringstreams are useful for "pre-building" formatted strings:
#include <iomanip>
#include <ios>
#include <iostream>
#include <sstream>
int main()
{
double value(27000);
std::ostringstream oss;
oss << std::setprecision(2) << std::fixed;
oss << value << "Cents";
std::cout << std::left;
std::cout << std::setw(20) << "BALANCE" << '\n';
std::cout << std::setw(20) << oss.str() << '\n';
return 0;
}
Output:
BALANCE
27000.00Cents
-Mike