C++ 错误:程序中出现“\240”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29311672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: stray '\240' in program
提问by Abraham
It is wanted of me to implement the following function:
我希望实现以下功能:
void?calc?(?double*?a,?double*?b,?int?r,?int?c,?double?(*f)?(double)?)
Parameters?a,?r,?c?and?f?are?input?and?b?is?output.?“a”?and?“b”?are?2d?matrices?with?“r”?rows?and?“c”? columns.?“f”?is?a?function?pointer?which?can?point?to?any?function?of?the?following?type:
参数?a,?r,?c?and?f?are?input?and?b?is?output.?“a”?and?“b”?are?2d?matrices?with?“r”?rows ?和?“c”?列。?“f”?是?a?函数?指针?哪个?可以?指向?任何?函数?的?以下?类型:
double?function‐name?(?double?x?)?{?
????…?
}?
Function?calc
?converts?every?element?in?matrix?a,?i.e.,?aij,?to?bij=f(aij)?in?matrix?b.??
功能?calc
?转换?每个?元素?输入?矩阵?a,?ie,?aij,?to?bij=f(aij)?in?matrix?b.??
I implement the calc
function as follows, and put it in a program to test it:
我实现了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;
}
The problem is, I can't compile it. This is the output of DevC++when I click on Compile and Executebutton :
问题是,我无法编译它。这是当我点击编译和执行按钮时DevC++的输出:
What's wrong?
怎么了?
I appreciate any comment to make the implementation more efficient.
我感谢任何评论,以提高实施效率。
采纳答案by sehe
It appears you have illegal characters in your source. I cannot figure out what character \240
should be but apparently it is around the start of line 10
您的来源中似乎有非法字符。我不知道\240
应该是什么字符,但显然它在第 10 行的开头
In the code you posted, the issue does not exist: Live On Coliru
在您发布的代码中,该问题不存在:Live On Coliru
回答by the sudhakar
As mentioned in a previous reply, this generally comes when compiling copy pasted code. If you have a bash shell, the following command generally works:
正如之前的回复中提到的,这通常发生在编译复制粘贴的代码时。如果您有 bash shell,则以下命令通常有效:
iconv -f utf-8 -t ascii//translit input.c > output.c
回答by Vishesh Gautam
The /240
error is due to illegal spaces before every code of line.
该/240
错误是由于线的每个代码之前非法的空间。
eg.
例如。
Do
做
printf("Anything");
instead of
代替
printf("Anything");
This error is common when you copied and pasted the code in the IDE.
当您在 IDE 中复制和粘贴代码时,此错误很常见。
回答by Abraham Solomon
Your Program has invalid/invisible characters in it. You most likely would have picked up these invisible characters when you copy and past code from another website or sometimes a document. Copying the code from the site into another text document and then copying and pasting into your code editor may work, but depending on how long your code is you should just go with typing it out word for word.
您的程序中包含无效/不可见字符。当您从另一个网站或文档中复制和粘贴代码时,您很可能会发现这些不可见字符。将代码从站点复制到另一个文本文档,然后复制并粘贴到代码编辑器中可能会起作用,但根据代码的长度,您应该逐字逐句地输入。
回答by Ajay
I got the same error when I just copied the complete line but when I rewrite the code again i.e. instead of copy-paste, writing it completely then the error was no longer present.
当我只是复制完整行时,我遇到了同样的错误,但是当我再次重写代码时,即而不是复制粘贴,完全写入它然后错误不再存在。
Conclusion: There might be some unacceptable words to the language got copied giving rise to this error.
结论:可能有一些不可接受的语言被复制导致了这个错误。
回答by rocksyne
SOLUTION:DELETE THAT LINE OF CODE [*IF YOU COPIED IT FROM ANOTHER SOURCE DOCUMENT] AND TYPE IT YOURSELF.
解决方案:删除该行代码 [*如果您从另一个源文档中复制它] 并自己输入。
Error: stray '\240' in programis simply a character encoding error message.
Error:stray '\240' in program只是一个字符编码错误信息。
From my experience, it is just a matter of character encoding. For example, if you copy a piece of code from a web page or you first write it in a text editor before copying and pasting in an IDE, it can come with the character encoding of the source document or editor.
根据我的经验,这只是字符编码的问题。例如,如果您从网页中复制一段代码,或者在复制和粘贴到 IDE 之前先在文本编辑器中编写它,则它可能带有源文档或编辑器的字符编码。
回答by Simon van Eeden
I faced the same problem due to illegal spaces in my entire code.
由于整个代码中的非法空格,我遇到了同样的问题。
I fixed it by selecting one of these spaces and use find and replace
to replace all matches with regular spaces.
我通过选择这些空格之一来修复它,并使用find and replace
常规空格替换所有匹配项。