Description
C++的输入输出使用cin 和cout函数,这两个函数存在于** <iostream>** 头文件中。
在C语言中,输出和输出一般需要指明变量的类型,而在C++中,输入和输出无须指明变量的类型。eg:
int number1;
float number2;
char x;
scanf("%d%f%c", &number1, &number2, &x);
以上的C语言程序在C++中为
#include <iostream> // 包含输入输出函数的头文件
using namespace std; // 命名空间,详细含义在以后了解,如果不加这一句,cin会报错
int number1;
float number2;
char x;
cin >> number >> number2 >> x;
如果在上面的程序中不加上** using namespace std; **,则需要改为std::cin >> number >> number2 >> x; 输出:
#include <iostream>
std::cout << "hello world!" << std::endl; // endl == '\n'
请使用C++的输入输出进行练习。