返回信息流#include <iostream>
using namespace std;
int main()
{
int n,i,j;
cin>>n;
int a[n];
for( i=0,i<=n,i++)
cin>>a[i];
for( j=0,j<=n,j++)
cout<<a[j];
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #72316同步于 2013/7/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
大神不要喷我。求解释~
alfred1993
2013/7/3镜像同步15 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 alfred1993 (alfred) 的大作中提到: 】
: 标 题: 大神不要喷我。求解释~
: 发信站: 北邮人论坛 (Wed Jul 3 10:34:51 2013), 站内
:
: #include <iostream>
: using namespace std;
: int main()
: {
: int n,i,j;
: cin>>n;
: int a[n];
n不是编译器决定的
: for( i=0,i<=n,i++)
: cin>>a[i];
: for( j=0,j<=n,j++)
: cout<<a[j];
: return 0;
: }
: --
:
: ※ 来源:·北邮人论坛 http://bbs.byr.cn·[FROM: 10.8.90.*]
一定要喷你~嘿嘿~
【 在 alfred1993 的大作中提到: 】
: #include <iostream>
: using namespace std;
: int main()
: ...................
C++的数组的下标是编译时决定的(当然,c99允许你这样写,但是C++不行)
for循环的括号里的三个表达式用分号;而不是逗号,分割。
循环次数不对。
p.s. 喷一下lz:[ema2]
p.s. 顺便贴一下编译器的输出:
$ cat vla.cpp
#include <iostream>
using namespace std;
int main()
{
int n,i,j;
cin>>n;
int a[n];
for( i=0;i<=n;i++)
cin>>a[i];
for( j=0;j<=n;j++)
cout<<a[j];
return 0;
}
$ clang++ -pedantic -o vla vla.cpp
vla.cpp:7:11: warning: variable length arrays are a C99 feature
[-Wvla-extension]
int a[n];
^
1 warning generated.
#include <iostream>
using namespace std;
int main()
{
int n,i,j;
cin>>n;
int *a=new int[n];
for( i=0;i<n;i++)
cin>>a[i];
for( j=0;j<n;j++)
cout<<a[j];
delete []a;
return 0;
}
【 在 alfred1993 的大作中提到: 】
: #include <iostream>
: using namespace std;
: int main()
: ...................
C++的数组的下标是编译时决定的~~这个是什么意思?我把都好改成分号后,貌似可以了。
【 在 nuanyangyang 的大作中提到: 】
: C++的数组的下标是编译时决定的(当然,c99允许你这样写,但是C++不行)
: for循环的括号里的三个表达式用分号;而不是逗号,分割。
: 循环次数不对。
: ...................
这个需要改成指针吗
【 在 zmbupt 的大作中提到: 】
: #include <iostream>
: using namespace std;
: int main()
: ...................
不好意思,口误了。C++的数组类型的变量的长度是编译时决定的。
也就是说,这个数字要“写死”在程序里,要用常数,而不是读入一个数然后创建这么长的数组变量。
如果要读入一个长度,你可以用vector,或者自己用new语句创建一个数组。
【 在 alfred1993 的大作中提到: 】
: C++的数组的下标是编译时决定的~~这个是什么意思?我把都好改成分号后,貌似可以了。
但是我刚才用C free编译了一下可以运行呀
【 在 nuanyangyang 的大作中提到: 】
: 不好意思,口误了。C++的数组类型的变量的长度是编译时决定的。
: 也就是说,这个数字要“写死”在程序里,要用常数,而不是读入一个数然后创建这么长的数组变量。
: 如果要读入一个长度,你可以用vector,或者自己用new语句创建一个数组。
: ...................