P
paul.wilkins
Hi,
I have a function I have written that works with g++ 2.95.3 that I
would like to use with newer g++ compilers >= 3.2.0. The function is a
stream manipulator similar to setw(). The code does not compile with
newer versions of g++. Please help me port this code.
Thanks,
-Paul
#include <iostream.h>
#include <iomanip.h>
int x = 1;
ios& temp_setw(ios & o, int n) { if(x) o.width(n); return o; }
smanip<int> my_setw(int n) { return smanip<int> (temp_setw,n); }
int main(int argc,char *argv[]) {
int a = 234;
x = 1; cout << a << my_setw(11) << "test" << endl;
x = 0; cout << a << my_setw(11) << "test" << endl;
}
I have a function I have written that works with g++ 2.95.3 that I
would like to use with newer g++ compilers >= 3.2.0. The function is a
stream manipulator similar to setw(). The code does not compile with
newer versions of g++. Please help me port this code.
Thanks,
-Paul
#include <iostream.h>
#include <iomanip.h>
int x = 1;
ios& temp_setw(ios & o, int n) { if(x) o.width(n); return o; }
smanip<int> my_setw(int n) { return smanip<int> (temp_setw,n); }
int main(int argc,char *argv[]) {
int a = 234;
x = 1; cout << a << my_setw(11) << "test" << endl;
x = 0; cout << a << my_setw(11) << "test" << endl;
}