📄 基本数据类型.txt
字号:
cout<<"\x07operating \tsystem\n"; //实现响铃且显示
//cout的一种用法,提高可读性
cout<<"My Name is Jone \n"
<<"the ID is "
<<2
<<endl;
//*************************
//** ch2_1.cpp **
//*************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
double amount = 22.0/7;
cout<<amount<<endl;
cout<<setprecision(0)<<endl
<<setprecision(1)<<endl
<<setprecision(2)<<endl
<<setprecision(3)<<endl
<<setprecision(4)<<endl;
cout<<setiosflags(ios::fixed);
cout<<setprecision(8)<<amount<<endl;
cout<<setiosflags(ios::scientific)<<amount<<endl;
cout<<setprecision(6);
}
//设置值的输出宽度 setw()
cout<<setw(8) //cmp the two display results
<<10
<<20
<<endl;
cout<<setw(8)<<10
<<setw(8)<<20
<<endl;
//*************************
//** ch2_2.cpp **
//*************************
#include <iostream.h>
void main()
{
int number =1001;
cout<<"Decimal:"<<dec<<number<<endl
<<"Hexadecimal:"<<hex<<number<<endl
<<"Octal:"<<oct<<number<<endl;
}
//**************************
//** ch2_2e.cpp **
//**************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
int number =1001;
cout<<"Hexadecimal:"<<hex
<<setiosflags(ios::uppercase)
<<number<<endl;
}
//*************************
//** ch2_3.cpp **
//*************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
cout<<setfill('*')
cout<<setw(2)<<21<<endl
cout<<setw(3)<<21<<endl
cout<<setw(4)<<21<<endl;
cout<<setfill('');
}
//*************************
//** ch2_4.cpp **
//*************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
cout<<setiosflags(ios::right)
<<setw(5)<<1
<<setw(5)<<2
<<setw(5)<<3<<endl;
cout<<setiosflags(ios::left)
<<setw(5)<<1
<<setw(5)<<2
<<setw(5)<<3<<endl;
}
//*************************
//** ch2_5.cpp **
//*************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
cout<<10.0/5<<endl;
cout<<setiosflags(ios::showpoint)
<<10.0/5<<endl;
}
//*************************
//** ch2_6.cpp **
//*************************
#include <iostream.h>
#include <iomanip.h>
void main()
{
cout<<10<<" "<<-20<<endl;
cout<<setiosflags(ios::showpos)
<<10<<" "<<-20<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -