c语言输出翻译成C++

#include <stdio.h>

void main ()
{
int stu[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19};
int cout = 0;
int cout1 = 3;
int *p = &stu[2];
int pu;

while ( cout <= 20 )
{
if ( cout1 == 3 )
{
cout1 = 0;
pu = p-stu;
printf (" %d ", stu[pu]);
stu[pu] = -1;
}
p = &stu[( ( ( p - stu ) + 1 ) % 20 )];
if (*p != -1)
{
cout = 0;
cout1++;
}
else cout++;
}

}

帮我结合源文件把printf (" %d ", stu[pu]);写成C++语句,在线等。
能编译成功答案一样就行了。
to:kl_heker 不行啊,答案都不一样的

#include <iostream> //修改头文件
using namespace std;
void main ()
{
int stu[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19};
int cout0 = 0;
int cout1 = 3;
int *p = &stu[2];
int pu;

while ( cout0 <= 20 )
{
if ( cout1 == 3 )
{
cout1 = 0;
pu = p-stu;
cout<<' '<<stu[pu]<<' '; //修改输出
stu[pu] = -1;
}
p = &stu[( ( ( p - stu ) + 1 ) % 20 )];
if (*p != -1)
{
cout0 = 0;
cout1++;
}
else cout0++;
}

}

cout改成cout0,cout在C++中是用于输出的,跟变量以示区别
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-08-01
#include <iostream>
然后吧stdio去了
替换printf (" %d ", stu[pu]); 为
cout<<stu[pu];
就行了
第2个回答  2007-08-01
cout<<stu[pu];
第3个回答  2007-08-01
如果你是vs200X的编译器的话,
#include <iostream>
using namespace std;
第4个回答  2007-08-01
在C++中cout是iosream标准库里的既有对象,你定义了一个cout的变量在C里没问题,在C++里就是灾难,把变量名改成cnt或其它不冲突的名字,再试试

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网