1

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?

meta_warrior
  • 389
  • 1
  • 6
  • 18

1 Answers1

2

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.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80