diff options
author | biao716.wang <biao716.wang@samsung.com> | 2020-03-19 01:04:30 +0900 |
---|---|---|
committer | biao716.wang <biao716.wang@samsung.com> | 2020-03-19 01:04:30 +0900 |
commit | 1d6613f4446f69f63beddf2d97c201154fb35e33 (patch) | |
tree | f32eae75900a0df14ab8fa1e2bd436af159ef91d /Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx | |
parent | aabcd8e66e3268a232efe2e416635d5b6bf84ad5 (diff) | |
download | cmake-upstream/3.16.4.tar.gz cmake-upstream/3.16.4.tar.bz2 cmake-upstream/3.16.4.zip |
Imported Upstream version 3.16.4upstream/3.16.4
Change-Id: Ic5262ea6c0872b353ea2dc35fe1e944063ae8409
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
Diffstat (limited to 'Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx')
-rw-r--r-- | Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx b/Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx new file mode 100644 index 000000000..ee585568c --- /dev/null +++ b/Help/guide/tutorial/Complete/MathFunctions/MakeTable.cxx @@ -0,0 +1,25 @@ +// A simple program that builds a sqrt table +#include <cmath> +#include <fstream> +#include <iostream> + +int main(int argc, char* argv[]) +{ + // make sure we have enough arguments + if (argc < 2) { + return 1; + } + + std::ofstream fout(argv[1], std::ios_base::out); + const bool fileOpen = fout.is_open(); + if (fileOpen) { + fout << "double sqrtTable[] = {" << std::endl; + for (int i = 0; i < 10; ++i) { + fout << sqrt(static_cast<double>(i)) << "," << std::endl; + } + // close the table with a zero + fout << "0};" << std::endl; + fout.close(); + } + return fileOpen ? 0 : 1; // return 0 if wrote the file +} |