永发信息网

C++,Code::Blocks 13.12里auto语句不能通过编译

答案:3  悬赏:80  手机版
解决时间 2021-02-12 16:37
  • 提问者网友:感性作祟
  • 2021-02-11 18:37
#include

struct antarctica_years_end
{
int year;
};

int main()
{
antarctica_years_end s01, s02, s03;
s01.year = 1998;
antarctica_years_end *pa = &s02;
pa->year = 1999;
antarctica_years_end trio[3];
trio[0].year = 2003;
std::cout << trio->year << std::endl;
const antarctica_years_end *arp[3] = {&s01, &s01,&s03};
std::cout << arp[1]->year << std::endl;
const antarctica_years_end **ppa = arp;
auto ppb = arp; // 报错:“ppb” does not name a type
std::cout << (*ppa)->year << std::endl;
std::cout << (*(ppb+1))->year << std::endl;
return 0;
}
上边是《C++ primer plus》里的范例
于是我试了试
int a[3] = {1, 2, 3};
auto b = a;
std::cout << b[1] << std::endl;
也是报一样的错

求解 - -
最佳答案
  • 五星知识达人网友:躲不过心动
  • 2021-02-11 20:00
请更新编译器。如果你用的不是最新的版本,也许不会认识这个用法。
全部回答
  • 1楼网友:独行浪子会拥风
  • 2021-02-11 21:25
1,首先确定你的linux的locale使用的是什么编码 linux 默认使用utf-8字符编码。 2,查看code::blocks的设置,看编辑器默认编码是什么 如果编写程序的编码和系统环境字符编码不同就会出现乱码
  • 2楼网友:鸠书
  • 2021-02-11 21:10
auto就是auto int的意思,一个int型的变量b怎么能给赋值为一个数组名?,所以auto b = a;是错误的。要时auto b = a[0]或auto b = a[1]什么的就对了,类型才能匹配。或者你把b声明为指针,auto *b=a也就对了。 ;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯