Reputation: 409
ZZ can output in c++ using
cout << ZZ;
because NTL is a c++ library.
However, how can i output ZZ in C using printf
, or convert ZZ to a string
?
Upvotes: 1
Views: 2068
Reputation: 33046
You can use stringstream
to print (convert) ZZ
to a string
:
#include <sstream>
#include <string>
std::string zToString(const ZZ &z) {
std::stringstream buffer;
buffer << z;
return buffer.str();
}
EDIT: You can get a C string from a std::string
using .c_str()
method, but if you want an independent C string back, then you can strdup
it:
#include <cstring>
char *zzstring = strdup(zToString(z).c_str());
and remember to free(zzstring)
before it goes out of scope.
Upvotes: 2