C++ Exercises(四)

本文探讨了C++中布尔值输出的差异,并通过多个示例介绍了文件读写、图形打印、素数筛选等实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,cout<<boolalpha<<(2>3)<<endl;输出什么?

Dev c++上输出false,VC++输出0,why?

2,

我机子上的VC6.0上编译通不过,可Dev C++可以运行,why?
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->#include<fstream>
usingnamespacestd;

intmain()
{
ifstream
in("F://data.txt");
ofstream
out("F://a.txt");
for(stringstr;getline(in,str);)
out<<str<<endl;
return0;
}

3
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->#include<iostream>
usingnamespacestd;

voidOutPutLine(introw)
{
inti;
for(i=4-row;i>0;i--)
cout
<<"";
for(i=2*row-1;i>0;i--)
cout
<<"*";
cout
<<endl;
}
intmain()
{
inti;
for(i=1;i<=4;i++)
OutPutLine(i);
for(i=3;i>=1;i--)
OutPutLine(i);
return0;
}

4
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->#include<iostream>
usingnamespacestd;

voidOutPutLine(introw)
{
inti;
for(i=1;i<=row-1;i++)
{
cout
<<"";
}
for(i=1;i<=21-2*row;i++)
{
cout
<<"M";
}
cout
<<endl;
}

intmain()
{
for(inti=1;i<=10;i++)
{
OutPutLine(i);
}
return0;

}
5
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->#include<iostream>
usingnamespacestd;

voidOutPutLine(introw)
{
inti;
charch='A';
for(i=1;i<=10-row;i++)
{
cout
<<"";
}
for(i=1;i<=2*row-1;i++)
{
cout
<<ch;
ch
++;
}
cout
<<endl;
}

intmain()
{
for(inti=1;i<=10;i++)
{
OutPutLine(i);
}
return0;

}
6
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->/*筛法求素数*/

#include
<iostream>
#include
<vector>
usingnamespacestd;

constintLEN=101;
vector
<int>b(LEN,1);

voidShaiSu()
{
inti,j;

for(i=2;i<LEN;i++)
{
if(b[i]==1)
{
for(j=2;i*j<LEN;j++)
{
b[i
*j]=0;
}
}
}
}

voidOutPut()
{
inti;
for(i=2;i<len;i++)
{
if(b[i]==1)
{
cout
<<i<<"是素数"<<endl;
}
}
}
intmain()
{
ShaiSu();
OutPut();
return0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值