c++问题 : expected primary-expression before '[' token

帮帮忙吧,初学者,可这个程序总也编译不了
#include <stack>
#include <iostream>
using namespace std;
#define M 10
stack <int> stack1,stack2;

int way[M+6][M+31]=
{
{'0','0','1','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'1','0','1','0','0','0','0','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'0','0','1','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'0','0','0','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1'},
{'1','1','1','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','0','1'},
{'1','1','0','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','0','5'}
};

int judge(int line,int col)
{
if (line==5)
{
return 1;
}
else
{
cout<<"ok"<<endl;
if(!((line==M)&&(col==M)))
{
cout<<line<<endl;
cout<<col<<endl;
cout<<M<<endl;

if((way[line][col+1]==0)&&([col+1<31]))
{
cout<<"ok2"<<endl;
col++;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else
{
if((way[line+1][col]==0)&&([line+1<6]))
{
cout<<"ok3"<<endl;

line++;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else if
{
((way[line][col-1]==0)&&([col-1>-1]))
{
cout<<"ok4"<<endl;
col--;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else if
{
((way[line-1][col]==0)&&(line-1>-1))
{
cout<<"ok5"<<endl;

line--;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else
{
cout<<"ok6"<<endl;

line=stack1.top();
col=stack2.top();
stack1.pop();
stack2.pop();

judge(line,col);

}
}
}
}
}

}
}
void print()

int main()
{
int line,col;
int judge;

cout<<"please insert the line colum "<<endl;
cin>>line,col;
judge(line,col);
return 0;
}

return 0;
}
}

line 37 error: expected primary-expression before '[' token
line 48 error:expected primary-expression before '['
line 59 error: expected '(' before '{' token
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input

//修改编译错误的办法:
//所有提示expected primary-expression before '&' token;的地方
//都把ArrayList&删掉
//以及将i和j的赋值语句改为i=list1.elems;j=list2.elems;

#include
#include
using namespace std;

#define INIT_SIZE 100
#define INC_SIZE 10

//定义一个线性表
typedef struct
{
int *elems;
int len;
int size;
}ArrayList;

ArrayList list1, list2, list3;

//初始化线性表
void init(ArrayList&list)
{
list.elems=(int *)malloc(sizeof(int)*INIT_SIZE);
list.len=0;
list.size=INIT_SIZE;
}

//打印顺序表
void print(ArrayList& list)
{
for (int i = 0; i < list.len; i++)
{
cout<<list.elems[i]<<"\n";
}
}

//销毁顺序表
void destroy(ArrayList& list)
{
free(list.elems);
list.len = 0;
list.size = 0;
}

//向顺序表index位置插入元素

void insert(ArrayList&list,int index,int e)
{
if(list.len>=list.size)
list.elems=(int *)realloc(list.elems, sizeof(int) * (INC_SIZE + list.size));

for(int i=list.len-1;i>=index;i--)
{
list.elems[i+1]=list.elems[i];
}

list.elems[index] = e;
list.len++;
}

//向顺序表末尾插入元素e
void add(ArrayList& list, int e)
{
insert(list, list.len, e);
}

//删除顺序表index位置的元素
void remove(ArrayList&list,int index)
{
for(int i=index;i<=list.len-2;i++)
{
list.elems[i]=list.elems[i+1];
}
list.len--;
}

//将1,2比较然后放入3中的函数
void merge(ArrayList&list1,ArrayList& list2,ArrayList& list3)
{
init(list3);
int *i,*j;int k=0;
i=list1.elems;
j=list2.elems;

for(int s=1;s<=list1.len && s<=list2.len;s++,i++,j++)
if(*i<*j)
{
insert(list3,k++,*i);
}
else insert(list3,k++,*j);
}

void testBasic()
{

init(list1);
init(list2);
init(list3);
add(list1, 3);
add(list1, 7);
add(list2, 2);
add(list2, 4);
add(list2, 5);
merge(list1, list2, list3);
print(list3);
destroy(list1);destroy(list2);destroy(list3);
}

int main()
{
testBasic();
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-11
第一 大括号数量不对,多了;
第二 else if {
((way[line][col-1]==0)&&([col-1>-1]))
……
是什么意思,if 判断语句竟然放到大括号里面……,还有像这样 &&[col-1>-1] ,加个方括号是什么意思
第三 void print() 只写只一句是干嘛呢,既不是声明也没定义
第四 main函数结束后的语句 是做什么?本回答被网友采纳
第2个回答  2011-04-15
住只有在定义字符数组的时候才可以用字符串给字符数组赋值。还有一个拼写错误,我也改过来了
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int number(0);
double number1(0);
double number2(0);
struct Convert
{
char convert_name[100];
double convert_rate;
};
Convert convert[3] = ,0.125},,};
cout<<"choose a way to convert money"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to pound"<<endl<<"3.yuan to pound";
cin>>number;
cout<<"please enter the type that you want to convert";
cin>>number1;
if(number<3&&number>=0)
number2=number1*convert[number-1].convert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<<number1<<convert[number-1].convert_name<<" is "<<number2;

system("PAUSE");
return EXIT_SUCCESS;
}
另外,团IDC网上有许多产品团购,便宜有口碑

c++问题 : expected primary-expression before '[' token
\/\/修改编译错误的办法:\/\/所有提示expected primary-expression before '&' token;的地方 \/\/都把ArrayList&删掉 \/\/以及将i和j的赋值语句改为i=list1.elems;j=list2.elems;include include using namespace std;define INIT_SIZE 100 define INC_SIZE 10 \/\/定义一个线性表 typedef struct { int *...

C++ expected primary-expression before ')' token
括号错了 include<iostream> using namespace std;int main(){ int n,i,j,q;((n>=1)&&(n<=10));cin>>n;for(i=1;i<=n;i++){ for(j=1;j<=2*i-1;j++){ cout<<"*";} for(q=n-1;q>=1;q--){\/\/你把这个打成小括号了 cout<<" "<<endl;}\/\/你把这个打成小括号...

...expected primary-expression before '.' token
第一种通过FDEV_SETUP_STREAM宏来定义流: (C编译器)static FILE mystdout = FDEV_SETUP_STREAM(dev_putchar, NULL,_FDEV_SETUP_WRITE);ststatic FILE mystdin = FDEV_SETUP_STREAM(NULL,dev_getchar, _FDEV_SETUP_READ);stdout=&mystdout;stdin=&mystdin;dev_putchar,dev_getchar分别是负责...

c++求救 编程出现expected primary-expression before ']' token
show_array(arr[][3],Asize);应改为:fill_array(arr,Asize);show_array(arr,Asize);根据你的函数定义,在这里只能传递数组的地址,而不是整个数组

...expected primary-expression before ';' token ,错误类似这个,求原 ...
你的程序的主要问题是没有分清类和对象的区别,对于指针p是指向对象的,而不是指向类的 你的C++程序我帮你改完了,你看看吧(改动的地方见注释)include<iostream>using namespace std;class Firgure{protected: float x_size; float y_size;public: Firgure(float a,float b) {x_size=a;y_size=...

expected initializer before'\/'token是什么意思?
意思是:C++的语法错误。2、expected initializer before '<' token.意思是:借鉴里面问没有指定名字空间的问题,重新把boost库的路径放到了答程序的属性->c++编译器->包含目录里面。3、expected primary-expression before '.' token.意思是:用avr-gcc编译是可以通过的,但用avr-c++就出现上面错误...

c++ Error] expected primary-expression before '||' token
if( 0 == year % 400 || ( 0 == year %4 && 0 != year %100 ) )

C++ expected primary-expression before '.' token.
按照C++03,可以写成 struct test_struct testing = {10, 20};但最好是用前一条回答说的,用分离的语句指定各成员变量的值

C++,16 expected primary-expression before ')'token
include<stdlib.h> int main(){ int x;int y;int z;char t;cout<<"输入运算中第一个数";cin>>x;cout<<"输入运算中第二个数";cin>>y;cout<<"输入如何运算,加或减";cin>>t;\/\/if下面的两个语句都是属于if之中的,要用大括号哦 否则要有两个输出,这两个输出就没有限制了,都要...

c++编译出错,expected primary-expression before '=' token.
= =为什么用空格分开……

相似回答