J
Joe C
I've written a console application and would like to isolate all screen
output so that it will be easier to migrate the code to a GUI-type platform
without modification to the base code. As a first step, I've created a
variable:
bool useConsole(true);
then I trap all output like:
if(useConsole){
cout << text;
}
However, I realized that having these traps dispersed throught the code was
a little sloppy, so I wrote a function:
void display(string text; useConsole){
if(useConsole){
cout << text;
}
}
which leads to the somewhat cleaner code where I simply say:
display(text, useConsole);
However, I also have some places in the code where I do things like:
string temp = fname;
cout.precision(4);
cout //<< "Success\t"
<< "Success\t"
<< setfill(' ')
<< setw(5)
<< static_cast<float>(clo)/CLOCKS_PER_SEC << " s\t"
<< ((temp.size() < 18) ? temp : temp.replace(7, (temp.size() - 17),
"\xaf")) // strip middle if too long to fit
<< endl;
My question--how can I dump this formatted output into a string that I can
then send to my display() function?
Thanks.
Merry Christmas
output so that it will be easier to migrate the code to a GUI-type platform
without modification to the base code. As a first step, I've created a
variable:
bool useConsole(true);
then I trap all output like:
if(useConsole){
cout << text;
}
However, I realized that having these traps dispersed throught the code was
a little sloppy, so I wrote a function:
void display(string text; useConsole){
if(useConsole){
cout << text;
}
}
which leads to the somewhat cleaner code where I simply say:
display(text, useConsole);
However, I also have some places in the code where I do things like:
string temp = fname;
cout.precision(4);
cout //<< "Success\t"
<< "Success\t"
<< setfill(' ')
<< setw(5)
<< static_cast<float>(clo)/CLOCKS_PER_SEC << " s\t"
<< ((temp.size() < 18) ? temp : temp.replace(7, (temp.size() - 17),
"\xaf")) // strip middle if too long to fit
<< endl;
My question--how can I dump this formatted output into a string that I can
then send to my display() function?
Thanks.
Merry Christmas