Objective: you have a floating point variable, and you want to apply iostream-type formatting to it so that it looks good in an Edit box. So instead of using iostream objects (like cout), we'll use strstream (string stream) objects that use a regular character array to hold the formatted character that ultimately need to be displayed.
Key concepts -
You need to include
Filenames used in the project --
format.aps format.clw format.cpp format.dsp format.dsw format.hres directory --
format.ncb format.opt format.plg format.rc FormatDlg.cpp FormatDlg.h readme.txt
resource.h stdafx.cpp stdafx.h
#include <strstrea.h>Code needed to go with the 'Format' button --
#include <iomanip.h>
void CFormatDlg::OnOK()
{
float x;static char chararray[10];
static ostrstream stringStream(chararray, 10);UpdateData(TRUE);
x = m_textbox;stringStream << setiosflags(ios::fixed) << setprecision(2) <<setiosflags(ios::showpoint) << x << ends;
m_textbox = atof(chararray);
UpdateData(FALSE);
stringStream.seekp(0); //resets the stream for susequent uses
//MessageBox(chararray);
//uncomment this, and then input 1.9978 and see what happens}
No, you can't redo lab 3 !!
Created & Maintained by DrB on Mon, Oct 23, 2000