首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如此奇怪的异常

2012-02-07 
如此奇怪的错误#includeiostream#includecstdlibusing namespace stdstruct test{int digits[3][3]}

如此奇怪的错误
#include<iostream>
#include<cstdlib>
using namespace std;
struct test
{
 int digits[3][3];
};
 
int main()
{
 
test t;
t.digits[3][3] = { 
  {2,3,4},
  {5,2,42},
{1,4,9}
};
return 0;
}

出现如下错误:

13 C:\Documents and Settings\Administrator\桌面\123.cpp expected primary-expression before '{' token 
13 C:\Documents and Settings\Administrator\桌面\123.cpp expected `;' before '{' token

[解决办法]
数组,不能直接赋值。除非是在定义的时候。
[解决办法]

C/C++ code
#include <iostream>using namespace std;intmain(int argc, char** argv){ int a1[]={1,2,3}; int a2[]={4,5,6}; a1=a2;    //error! return 0;}a1=a2;似乎没错的,指针赋值...但这个程序编译无法通过.为何?1.数组名虽然是一个指针,但他是一个const指针!2.只有对左值(lvalue)才可以做赋值操作.3.而常量指针是一个右值. 

热点排行