将坐标从数学函数导出到 C++ 中的 .txt 文件
Export coordinates from a math function to a .txt file in C++
我的任务是取一个数学函数,比如
f(x) = 10 ∗ sin(x)
并将其坐标的子集导出到 .txt 文件中。有什么好的方法吗?
您可以使用 std::ofstream
.
将坐标导出到文本文件中
#include <iostream>
#include <fstream>
#include <cmath>
double func(int x){
return 10 * sin(x); // your function here
}
int main(){
ofstream fout("coordinates.txt"); // declares an output file stream to
// "coordinates.txt" called fout
for(int i = 0; i < 100; ++i){
fout << i << ": " << func(i) << endl;
}
return 0;
}
我的任务是取一个数学函数,比如
f(x) = 10 ∗ sin(x)
并将其坐标的子集导出到 .txt 文件中。有什么好的方法吗?
您可以使用 std::ofstream
.
#include <iostream>
#include <fstream>
#include <cmath>
double func(int x){
return 10 * sin(x); // your function here
}
int main(){
ofstream fout("coordinates.txt"); // declares an output file stream to
// "coordinates.txt" called fout
for(int i = 0; i < 100; ++i){
fout << i << ": " << func(i) << endl;
}
return 0;
}