← 返回首页
C++基础教程(三)
发表时间:2023-07-21 16:19:09
输入和输出

cin和cout是C++中最常用的输入和输出工具。它们是iostream标准库中的一部分,需要包含头文件才能使用。cin用于从键盘读取输入,而cout用于向屏幕输出结果。

1.输入输出实例

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string name;
    int age;
    cout<<"please input your name and age!"<<'\n';
    cin>>name>>age;
    cout<<"welcome: "<<name<<endl;
    cout<<"your age is:"<<age<<endl;
    getchar();
    return 0;
}