C++ CRC编码程序中的编译错误
我为执行CRC编码的程序编写了以下代码。我以课堂上教我们的C程序为模型。它给出了一些我无法纠正的编译错误。我在代码后面提到了它们C++ CRC编码程序中的编译错误,c++,C++,我为执行CRC编码的程序编写了以下代码。我以课堂上教我们的C程序为模型。它给出了一些我无法纠正的编译错误。我在代码后面提到了它们 I wrote the following code for a program that performs CRC encoding. I modeled it on a C program that we were taught in class. It gives some compilation errors that I can't correct. I h
I wrote the following code for a program that performs CRC encoding. I modeled it on a C program that we were taught in class. It gives some compilation errors that I can't correct. I have mentioned them after the code.
1 #include<iostream>
2 #include<string.h>
3
4 using namespace std;
5
6 class crc
7 {
8 char message[128],polynomial[18],checksum[256];
9 public:
10 void xor()
11 {
12 for(int i=1;i<strlen(polynomial);i++)
13 checksum[i]=((checksum[i]==polynomial[i])?'0':'1');
14 }
15 crc() //constructor
16 {
17 cout<<"Enter the message:"<<endl;
18 cin>>message;
19 cout<<"Enter the polynomial";
20 cin>polynomial;
21 }
22 void compute()
23 {
24 int e,i;
25 for(e=0;e<strlen(polynomial);e++)
26 checksum[e]=message[e];
27 do
28 {
29 if(checksum[0]=='0')
30 xor();
31 for(i=0;i<(strlen(polynomial)-1);i++)
32 checksum[i]=checksum[i+1];
33 checksum[i]=message[e++];
34 }while(e<=strlen(message)+strlen(checksum)-1);
35 }
36 void gen_proc() //general processing
37 {
38 int mesg_len=strlen(message);
39 for(int i=mesg_len;i<mesg_len+strlen(polynomial)-1;i++)
40 message[i]='0';
41 message[i]='\0'; //necessary?
42 cout<<"After appending zeroes message is:"<<message;
43 compute();
44 cout<<"Checksum is:"<<checksum;
45 for(int i=mesg_len;i<mesg_len+strlen(polynomial);i++)
46 message[i]=checksum[i-mesg_len];
47 cout<<"Final codeword is:"<<message;
48 }
49 };
50 int main()
51 {
52 crc c1;
53 c1.gen_proc();
54 return 0;
55 }
我一直在在线检查这些错误,唯一看到的是错误的数组处理导致的错误。我已经仔细检查了我的代码,但是我好像没有执行任何错误的数组访问。C++中的< > > >代码> XOR <代码>是一个保留关键字。您应该将该函数重命名为其他函数
编译器实际上并没有“看到”一个标识符,而是一个关键字。如果在代码段中,用<代码> ^ < />代码替换<代码> XOR >代码>,明显的语法错误就变得明显了。
<代码> XOR <代码>是C++中的保留关键字。您应该将该函数重命名为其他函数
编译器实际上并没有“看到”一个标识符,而是一个关键字。如果在代码片段中,您将
xor
替换为^
,那么明显的语法错误就会变得很明显。就是这样。非常感谢:)编译器没有“看到”a^
,但是关键字xor
与a^
的含义完全相同。我会向编译器供应商报告一个错误:当没有错误时抱怨^
就不能被认为是正确的。就是这样。非常感谢:)编译器没有“看到”a^
,但是关键字xor
与a^
的含义完全相同。我会向编译器供应商报告一个错误:当没有错误时,抱怨^
是不正确的。
crc.cpp:10: error: expected unqualified-id before ‘^’ token
crc.cpp: In member function ‘void crc::compute()’:
crc.cpp:30: error: expected primary-expression before ‘^’ token
crc.cpp:30: error: expected primary-expression before ‘)’ token
crc.cpp: In member function ‘void crc::gen_proc()’:
crc.cpp:41: warning: name lookup of ‘i’ changed for ISO ‘for’ scoping
crc.cpp:39: warning: using obsolete binding at ‘i’