Convert polynomial ZZX or ZZ_pX to string

939 views Asked by At

NTL how to convert polynomial (ZZX or ZZ_pX) to string and how to assign string input to the polynomial like cin and cout operators?

I tried like the following:

ZZX a = conv<ZZX>("[2 3 12]")

But it gets error.

1

There are 1 answers

0
AbcAeffchen On

As you can read from your error message: There is no function conv that converts a string to a polynomial or the other way around.

You can use << on all NTL objects, e.g.

ZZX p;
p.SetLength(3);
p[0] = 0; p[1] = 1; p[2] = 2;
cout << p << endl;             // output: [0 1 2]

To read a string into a ZZX object you need to write your own function. This depends on how you actually get your input. If you read it from a file, you need to get the numbers from the string and set them via the [] operator. If you input it via the console, you can skip the string and directly build the ZZX object.

Finally you can use this to overload the conv function.