baigoo 2014年01月05日
c++ 程序意想不到的简洁清晰

//============================================================================
// Name : std1.cpp
// Author : chenyan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <iomanip>
#include <locale>
using namespace std;

class A{
public:
A(){total++;cout << "调用无参构造函数" << endl;};
A(int num):it(num){total++;cout << "调用有参构造函数" << endl;}
~A(){total--;}
static int total;
void set(int num){it = num;}
int get(){return it;}
private:
int it;
};
int A::total = 0;

int main() {
A mya;
char ch = 'a';
const double PI = 3.1415926;
int a = 0X10;
mya.set(100);
cout << "mya.tatal="<< mya.total << endl;
cout <<"mya.it="<< mya.get() << endl;
cout << "OCT:"<< oct << "a=0"<< a << endl; //以八进制显示
cout << "DEC:"<< dec << "a="<< a << endl; //以十进制显示
cout << "HEX:"<< hex << "a=0X"<< a << endl; //以十六进制显示
cout << "ASCII:'"<< ch << "'=" << (int)ch << endl;//字符a的ASCII码
cout << dec;//下面全部内容以十进制格式显示
cout <<"bool "<<"false:"<<false <<" true:"<< true << endl;
cout << "char:"<<sizeof(char)<<endl;
cout << "wchar_t:"<<sizeof(wchar_t)<<endl;
cout << "short:"<<sizeof(short)<<endl;
cout << "unsigned int:"<<sizeof(unsigned int)<<endl;
cout << "signed int:"<<sizeof(signed int)<<endl;
cout << "long int:"<<sizeof(long int)<<endl;
cout << "long long:"<<sizeof(long long)<<endl;
cout << "float:"<<sizeof(float)<<endl;
cout << "double:"<<sizeof(double)<<endl;
cout << "long double:"<<sizeof(long double)<<endl;//ANSI C99标准
cout << "double long:"<<sizeof(double long)<<endl;
cout << "PI="<< setprecision(8) << PI << endl;//设置输出的有效位为8位,cout默认最长
//输出精度为6位
for(int i = 1;i <= 9;i ++){
for(int j = 1;j <= i;j ++){
cout << j << "*" << i << "=" << i * j;
cout << "\t";
}
cout << endl;
}

return 0;
}


执行结果:

...全文
128 点赞 收藏 7
写回复
7 条回复

还没有回复,快来抢沙发~

发动态
发帖子
C++ 语言
创建于2007-09-28

3.1w+

社区成员

24.8w+

社区内容

C++ 语言相关问题讨论,技术干货分享
社区公告
暂无公告