gpt4 book ai didi

c++ - 编译器提示 "Error: stray '\24 0' in program"

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:07:09 25 4
gpt4 key购买 nike

需要我实现以下功能:

void calc ( double* a, double* b, int r, int c, double (*f) (double) )

参数a、r、c、f为输入,b为输出。 “a”和“b”是具有“r”行和“c”的二维矩阵列。 “f”是一个函数指针,可以指向以下类型的任何函数:

double function‐name ( double x ) {

}

函数 calc 将矩阵 a 中的每个元素(即 aij)转换为矩阵 b 中的 bij=f(aij)。


我是这样实现calc函数的,放在程序中测试一下:

#include <stdlib.h>
#include <iostream>

using namespace std;

double f1(double x){
return x * 1.7;
}

void calc (double* a, double* b, int r, int c, double (*f) (double))
{
double input;
double output;

for(int i=0; i<r*c; i++)
{
input = a[i];
output = (*f)(input);
b[i] = output;
}
}

int main()
{
// Input array:
int r=3;
int c=4;
double* a = new double[r*c];
double* b = new double[r*c];

// Fill "a" with test data
//...

for (int i=0; i<r*c; i++)
{
a[i] = i;
}

// Transform a to b
calc(a, b, r, c, f1);

// Print to test if the results are OK
//...

for (int i=0; i<r*c; i++)
{
b[i] = i;
}

return 0;
}

问题是,我无法编译它。这是当我单击 Compile and Execute 按钮时 DevC++ 的输出:

Compilation errors referring to invalid characters

怎么了?

我感谢任何评论,以提高实现效率。

最佳答案

如之前的回复所述,这通常是在编译复制粘贴代码时出现的。如果您有 Bash shell,通常可以使用以下命令:

iconv -f utf-8 -t ascii//translit input.c > output.c

关于c++ - 编译器提示 "Error: stray '\24 0' in program",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29311672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com