I'm trying to format output using the NTL library (a number theory library). One of the objects is the GF2X object, which is a polynomial represented as a string of coefficients. A quick example:
GF2X a = GF2X(5,1);
a++;
cout<<a;
will yield [1 0 0 0 0 1]
which is the same as x^5 + 1. My question is about formatting this output using setw. I want to be able to output various length GF2X objects, prepended by a number, and appended with a string. I'd like my output to look like the following:
1: [x x x x x x x x] string here
15: [x x x] string here
I would also settle for the right ] to be aligned, which is what I should probably expect if I'm using setw. However, when i use the code (variable names ommitted for simplicity):
cout << setw(3)<< int <<": "<< setw(35) << GF2X << setw(15) << string << endl;
I get output more like this (some white space removed for compactness)
1: [x x x x x x x x] string here
15: [x x x] string here
In other words, the setw function seems to be treating the entire output of <<GF2X
as a single character, and doesn't seem to actually account for the size of the output string. As you can see from the output I've shown you, the left side of the GF2X output is aligned, but the right side isn't, whereas typically, setw seems to align the right side of outputs.