How can I format user input into a neat table for output in C++ -


i having problems getting table line correctly, cout statement table. problem how can format different things in 1 line without messing next entry in line. example, when use setprecision(2) goldweight, goldvalue gets messed , gives me weird number 5656e+02

 cout << "                   value analysis" <<endl; cout << "gold: " << setw(6) <<  "" <<goldweight<< "  oz @ "<<costgold<<" ("<<setw(1)<<    ""<<carats<<"         carats) $"<<goldvalue<<endl; 

yes, setw(), setprecision(), etc mess stuff. can use temporary std::ostringstream.

#include <sstream> ... std::ostringstream oss_goldweight ; std::ostringstream oss_goldvalue ; std::ostringstream oss_goldcarats ;  oss_goldweight << setw(6) << goldweight ; oss_goldvalue << setprecision(2) << goldvalue ; oss_goldcarats << setw(1) << carats ; 

and use oss_goldxyz variables instead of raw values.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -