错误 C2057:预期的常量表达式 [英] Error C2057: expected constant expression
本文介绍了错误 C2057:预期的常量表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if(stat("seek.pc.db", &files) ==0 )
sizes=files.st_size;
sizes=sizes/sizeof(int);
int s[sizes];
我正在 Visual Studio 2008 中编译它,但出现以下错误:错误 C2057:预期的常量表达式错误 C2466:无法分配常量大小为 0 的数组.
I am compiling this in Visual Studio 2008 and I am getting the following error: error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0.
我尝试使用向量 s[sizes] 但无济于事.我做错了什么?
I tried using vector s[sizes] but of no avail. What am I doing wrong?
谢谢!
推荐答案
必须在编译时知道 C 中数组变量的大小.如果你只在运行时知道它,你将不得不自己malloc
一些内存.
The sizes of array variables in C must be known at compile time. If you know it only at run time you will have to malloc
some memory yourself instead.
这篇关于错误 C2057:预期的常量表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文