C++ cout输出

在c++中,输出是必不可少的,cout是很常用的输出。在<iostream>中,有许许多多的内置函数,像cout,cin等等。把一个东西显示到屏幕上是cout的作用,当然,不是只有cout可以输出,像printf也可以。

如果不加 using namespace std ,可以 std::cout << 1; ,这样也可以输出。

标准输出(cout)

#include <iostream>
using namespace std;

int main()
{
    cout << 1 << endl;
    return 0;
}

执行以上代码会输出:

1

如果输出计算也可以:

cout << 1 + 1 << endl;

cout 也可以写成 “cout << 1;”这样,后面的 << endl;是换行的意思,如果输出字符可以用\n

输出字符(hello)

#include <iostream>
using namespace std;

int main()
{
    cout << "hello" << endl;
    return 0;
}

输出结果

hello

这是输出字符,想要换行后面加\n就可以了。

举例

1 输出数字

#include <iostream>
using namespace std;

int main()
{
    cout << 1 << endl;
    return 0;
}

2 输出字符

#include <iostream>
using namespace std;

int main()
{
    cout << "lo" << endl;
    return 0;
}

3 输出后换行

字符

#include <iostream>
using namespace std;

int main()
{
    cout << "hello\n" << endl;
    return 0;
}

数字

#include <iostream>
using namespace std;

int main()
{
    cout << 1 << endl;
    return 0;
}

感谢大家的观看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值