两个很小的问题

yunhaiC QQ654777694 2008-03-18 10:23:23
#include <iostream>
#include <iomanip>
#include <<cctype>
#include <conio.h>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
int main(){
int table=0;
const int table_min=2;
const int table_max=12;
char ch=0;
do{
cout<<endl
<<"What size table would you like{"
<<table_min<<" to "<<table_max<<"}?";
cin>>table;;
cout<<endl;
if(table<table_min||table>table_max){
cout<<"Invalid table size entered.Program terminated."
<<endl;
exit(1); //(1)
}
cout<<" |";
for(int i=1;i<=table;i++)
cout<<" "<<setw(3)<<i<<" |"; //(2)
cout<<endl;
for(int i=0;i<=table;i++)
cout<<"------";
cout<<endl;
for(int i=1;i<=table;i++){
cout<<" "<<setw(3)<<i<<" |";
for(int j=1;j<=table;j++)
cout<<" "<<setw(3)<<i*j<<" |";
}
cout<<endl;
cout<<endl<<"Do you want another table(y or n)?";
cin>>ch;
cout<<endl;
}while(std::tolower(ch)=='y');
getch();
return 0;
}

(1)exit(1)与break或者continue有什么区别?

(2)setw(n),到底输出多宽,是不是跟n的类型有关还是怎么?
...全文
107 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 fetag 的回复:]
引用 5 楼 yunhaiC 的回复:
英文没四级怎么看?

四级考下来的未必能看得懂我贴的东西...
[/Quote]

看文献六级就行了吧
有没看过"疯狂的程序员"小说?
学英语等于背单词,背单词就相当于被字典,有字典不查被字典这人有问题
ryfdizuo 2008-03-18
  • 打赏
  • 举报
回复
@_@
晕...过儿卖狗皮膏药了...
独孤过儿 2008-03-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yunhaiC 的回复:]
英文没四级怎么看?
[/Quote]
四级考下来的未必能看得懂我贴的东西...
  • 打赏
  • 举报
回复
英文没四级怎么看?
ttkk_2007 2008-03-18
  • 打赏
  • 举报
回复
continue不退出循环,直接进行下次循环
ttkk_2007 2008-03-18
  • 打赏
  • 举报
回复
exit(1)直接退出,并返回给系统1,break,coutinue推出类似于循环,switch这样的结构
setw(n),设置宽度为n,比如
cout << setw(3) << 23 << endl;
输出:空格23
独孤过儿 2008-03-18
  • 打赏
  • 举报
回复
1、exit(1)直接结束程序,并且给调用main()的进程返回一个1;而break和continue仅仅是在程序内部的结构语句之间跳出

2、第二个问题贴一个demo

smanip setw ( int n ); <iomanip>

Set field width

Sets the number of characters to be used as the field width for the next insertion operation.

Behaves as if a call to the stream's member ios_base::width with n as its argument was made.

The field width determines the minimum number of characters to be written in some output

representations. If the standard width of the representation is shorter than the field width, the

representation is padded with fill characters (see setfill) at a point determined by the format

flag adjustfield (left, right or internal).

This manipulator is declared in header <iomanip>, along with the other parameterized manipulators:

resetiosflags, setiosflags, setbase, setfill and setprecision. This header file declares the

implementation-specific smanip type, plus any additional operator overload function needed to allow

these manipulators to be inserted and extracted to/from streams with their parameters.


Parameters
n
Number of characters to be used as field width.

Return Value
Unspecified. This function should only be used as a stream manipulator.

Example
// setw example
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
cout << setw (10);
cout << 77 << endl;
return 0;
}


This code uses setw to set the field width to 10 characters.


独孤过儿 2008-03-18
  • 打赏
  • 举报
回复
1、exit(1)直接结束程序,并且给调用main()的进程返回一个1;而break和continue仅仅是在程序内部的结构语句之间跳出

2、第二个问题贴一个demo

smanip setw ( int n ); <iomanip>

Set field width

Sets the number of characters to be used as the field width for the next insertion operation.

Behaves as if a call to the stream's member ios_base::width with n as its argument was made.

The field width determines the minimum number of characters to be written in some output

representations. If the standard width of the representation is shorter than the field width, the

representation is padded with fill characters (see setfill) at a point determined by the format

flag adjustfield (left, right or internal).

This manipulator is declared in header <iomanip>, along with the other parameterized manipulators:

resetiosflags, setiosflags, setbase, setfill and setprecision. This header file declares the

implementation-specific smanip type, plus any additional operator overload function needed to allow

these manipulators to be inserted and extracted to/from streams with their parameters.


Parameters
n
Number of characters to be used as field width.

Return Value
Unspecified. This function should only be used as a stream manipulator.

Example
// setw example
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
cout << setw (10);
cout << 77 << endl;
return 0;
}


This code uses setw to set the field width to 10 characters.


zh1369 2008-03-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 yunhaiC 的回复:]
引用 6 楼 fetag 的回复:
引用 5 楼 yunhaiC 的回复:
英文没四级怎么看?

四级考下来的未必能看得懂我贴的东西...


看文献六级就行了吧
有没看过"疯狂的程序员"小说?
学英语等于背单词,背单词就相当于被字典,有字典不查被字典这人有问题
[/Quote]

说我那!!

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧