C++ 错误:“&引用;预期在“之前”;“无效”;
这可能很愚蠢,但我收到了一个错误,在头文件中的“void”之前应该是“code>”。 这不是写标题的正确方法吗 这是main,其中C++ 错误:“&引用;预期在“之前”;“无效”;,c++,header,C++,Header,这可能很愚蠢,但我收到了一个错误,在头文件中的“void”之前应该是“code>”。 这不是写标题的正确方法吗 这是main,其中pa1是标题的名称 #include <iostream> using namespace std #include "pa1.h" int main(){ cout<<"Enter the size of magic square: "; int n; cin>>n;
pa1
是标题的名称
#include <iostream>
using namespace std
#include "pa1.h"
int main(){
cout<<"Enter the size of magic square: ";
int n;
cin>>n; //Enter the size of the magic square
if(n%2!=0 && n>=3 && n<=15){ //If the number is odd and between 3 and 15 run the program
int m=n;
magicSquare(m);
}
else{
cout<<"Number is not odd or is out of range."<<endl;
}
return 0;
}
在magicsquare()
函数中,我首先创建了幻方,通过将每个值分配到正确的位置,以及创建幻方所需的各种条件,然后打印出幻方。
只有我写
,我才能让它工作标题中void
之前的code>此行前面可能有无法识别的字符。例如unicode空白。确保此行为空
#include <iostream>
using namespace std
#include "pa1.h"
int main(){
cout<<"Enter the size of magic square: ";
int n;
cin>>n; //Enter the size of the magic square
if(n%2!=0 && n>=3 && n<=15){ //If the number is odd and between 3 and 15 run the program
int m=n;
magicSquare(m);
}
else{
cout<<"Number is not odd or is out of range."<<endl;
}
return 0;
}
顺便说一句,如果在此文件之前包含的任何其他头文件中出现错误,也会导致此问题
在你的情况下,你失去了“;”在“使用名称空间标准”之后。错误很简单;您忘记在下列项之前添加分号:
using namespace std;
线路。当你加上它的时候,你应该没问题。这个标题本身就没问题。你把它包括在哪里?您在该包含项上有什么代码?你能给我们看一个吗?问题在于你在标题前包含了什么。仔细看一下你在#包含“pa.h”
之前的行。结尾不是少了点什么吗?我刚意识到我忘记了使用名称空间stdYeah的分号谢谢一些程序员伙计
using namespace std;