cin、cout 后缀名 cin(从键盘接收)、cout cin、cout例子

C语言:C
OC:m
JS:js
JAVA:java 先有类,再有函数 eclipse
C++:cpp c plus plus 完全兼容C语言,以前叫c with classes(带有类的C语言)

C++程序的入口是main函数(函数和方法一个意思和本质,汇编一模一样,随意叫)

cin(从键盘接收)、cout

cin、cout控制台的输入,输出
依赖于上下文

#include <iostream>
using namespace std;
cout << "test1";
cout << endl;
cout << "test2";
//等价于下面这个
cout << "test1" << endl << "test2";
//cin从键盘接收数据
int age;
cin >> age;
cout << "age is" << age << endl;

cin、cout例子

#include <iostream>
using namespace std;

int main() {
    cout << "please type a number:" << endl;

    int age;
    cin >> age;
    cout << "age is " << age << endl;

    getchar();
    return 0;

}
  • main函数退出,程序就结束了。

解决方案-右键-文件资源管理器打开文件夹 debug - exe文件 命令行执行以下
cin、cout
后缀名
cin(从键盘接收)、cout
cin、cout例子

  • getchar()等待键盘输入