Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 表达式结果未使用,图像生成_C++ - Fatal编程技术网

C++ 表达式结果未使用,图像生成

C++ 表达式结果未使用,图像生成,c++,C++,我正试图用这段代码生成一个圆形图像 #include <fstream> #include <iostream> #include <iomanip> using namespace std; double e, f; double scaler (double a, double b) { if (a < 256) { e = (-1) * a / 256.0; if (b < 256) {

我正试图用这段代码生成一个圆形图像

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

double e, f;

double scaler (double a, double b) {
    if (a < 256) {  e = (-1) * a / 256.0;
        if (b < 256) {
            f = b / 256.0;
        } else {
            f = (-1) * (b - 256.0) / 256.0;
        }
    } else { e = (a - 256.0) / 256.0;
        if (b < 256) {
            f = b / 256.0;
        } else {
            f = (-1) * (b - 256.0) / 256.0;
        }
    }
    return e, f;
}

int main () {

    int max_color = 255;
    int dimention = 512;

    ofstream fout;
    fout.open("mandeloutput.ppm");

    fout << "P3\n" << dimention << " " << dimention << endl << max_color << endl;
    for (int i = 0; i < dimention; i++) { f = i;
        for (int j = 0; j < dimention; j++) { e = j;
            scaler (e, f);
            cout << fixed << setprecision(5) << e << " " << f << endl;
            if ( e*e + f*f <= 1) {
                fout << right << setw(4) << 0 << setw(4) << 0 << setw(4) << 0 << "   ";
            } else {fout << right << setw(4) << 255 << setw(4) << 255 << setw(4) << 255 << "   ";}
        }
        fout << endl;
    }
} 
#包括
#包括
#包括
使用名称空间std;
双e,f;
双定标器(双a、双b){
如果(a<256){e=(-1)*a/256.0;
如果(b<256){
f=b/256.0;
}否则{
f=(-1)*(b-256.0)/256.0;
}
}否则{e=(a-256.0)/256.0;
如果(b<256){
f=b/256.0;
}否则{
f=(-1)*(b-256.0)/256.0;
}
}
返回e,f;
}
int main(){
int max_color=255;
整数维=512;
流式流量计;
fout.open(“mandeloutput.ppm”);

fout
返回e,f;
不做您认为它做的事情。逗号运算符只是计算并丢弃
e
,然后
f
的值作为函数结果返回。由于这些都是全局值,因此不需要从该函数返回任何内容,但最好不要使用全局值并执行此操作erly.删除全局声明
double e,f;
,并将函数更改为如下内容:

void scaler (int a, int b, double &e, double &f) {
    if (a < 256) {  e = (-1) * a / 256.0;
        if (b < 256) {
            f = b / 256.0;
        } else {
            f = (-1) * (b - 256.0) / 256.0;
        }
    } else { e = (a - 256.0) / 256.0;
        if (b < 256) {
            f = b / 256.0;
        } else {
            f = (-1) * (b - 256.0) / 256.0;
        }
    }
}
void scaler(int a、int b、double&e、double&f){
如果(a<256){e=(-1)*a/256.0;
如果(b<256){
f=b/256.0;
}否则{
f=(-1)*(b-256.0)/256.0;
}
}否则{e=(a-256.0)/256.0;
如果(b<256){
f=b/256.0;
}否则{
f=(-1)*(b-256.0)/256.0;
}
}
}
然后在主函数中更改以下行:

for (int i = 0; i < dimention; i++) { f = i;
    for (int j = 0; j < dimention; j++) { e = j;
        scaler (e, f);
        ...
for(inti=0;i
为此:

for (int i = 0; i < dimention; i++) {
    for (int j = 0; j < dimention; j++) {
        double e, f;
        scaler (j, i, e, f);
        ...
for(int i=0;i
拼写注意:您要查找的单词是