Search code examples
c++command-line-argumentsgmp

How do I store a file in a variable using GMP in C++?


I am using GMP, the GNU bignum library.

I'd like to read the entire contents of a file (preferrably from the command line) into an mpz_class integer so that I can perform arithmetic and whatnot on the file data.

Here is the essentials of what I would like to do:

int main(int argc, char* argv[]) {
  mpz_class theFile = atoi(argv[1]);

  ...
}

(you get the idea).

Obviously atoi() won't handle a bignum, so is there a way to do this without resorting to the C functions?


Solution

  • Since mpz_class has a constructor that takes a null-terminated string, the following should work:

    mpz_class theFile(argv[1]);