标准输入输出流cin、cout

//标准输入输出流使用示例

//:
#include <iostream>//C++标准输入输出流
#include <cstdlib>//C语言的标准输入输出流
#include <string>//C++的string类
using namespace std;
u
int main(void){
    cout<<"hello,"
        <<8<<",Today"<<std::endl;

    //打印十进制、八进制、十六进制
    cout<<"用十进制、八进制、十六进制显示数据"<<std::endl;
    cout<<"a number in decimal "<<dec<<15<<std::endl;
    cout<<"in octal: "<<oct<<15<<std::endl;//八进制,oct
    cout<<"in hex: "<<hex<<15<<std::endl;//十六进制,hex
    cout<<"a floating-point number "<<3.1415926<<std::endl;//编译器会自动确定浮点数的格式
    cout<<"non-printing char(espace): "<<char(27)<<std::endl;//任何字符都会转化成char类型(单字符数据类型)

    // C++字符数组的拼接
    cout<<"C++字符串拼接显示"<<std::endl;
    cout<<"This is far too long to put on a"
        "single line but it can be broken up with"
        "no ill effects \n as long as there is no"
        "punctuatation separating adjacent character"
        "arrays.\n"<<std::endl;

    //C++标准输入流
    cout<<"使用标准输入流向控制台输入数据"<<std::endl;
    int number;
    cin>>number;
    cout<<"value int octal=0"<<oct<<number<<std::endl;//用八进制把输入的数据打印出来
    cout<<"value in hex=0x"<<hex<<number<<std::endl;//用十六进制把输入的数据打印出来

    //C++使用C语言的库函数
    system("java -version");//向DOS批处理程序中输入字符串调用其他程序

    //使用C++的string类,用来处理并隐藏字符数组的低级操作
    cout<<"使用C++的string类\n";
    string s1,s2;
    string s3="Hello,World";
    string s4="I am";
    s2="Today";
    s1=s3+" "+s4;
    s1+=" 8 ";
    cout<<s1+s2+"!"<<std::endl;
    return 0;
}//:~

cin>> 、cout<<:其实就<<、>>是操作符重载,就相当于把一个值赋给一个对象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值