C++自学之路:2.3--其他C++语句

xiaoxiao2021-02-28  76

#include <iostream> int main(int argc, const char * argv[]) { using namespace std; int carrots; cout << "How many carrots do you have?" << endl; cin >> carrots; carrots = carrots + 2; cout << "Here are two more.Now you have " << carrots << " carrots." << endl; /* 1.和cout一样,cin也是一个智能对象。它可以将键盘输入的一系列字符转换成接受信息的变量能够接受的形式。 2.iostream定义了<<运算符,可以将四条输出语句合并为一条。下面这种方式代码易读。 */ cout << "Here are two more." << "Now you have " << carrots << " carrots." << endl; /* 1.类是用户定义的一种数据类型。需要描述它能够表示什么信息,可以对数据进行哪些操作。 2.类描述了一种数据类型的全部属性(包括可使用它进行的操作),对象是根据这些操作创建的实体。 3.iostream系列类和相关的fstream系列类是早期所有实现都自带的两组定义类。 4.C++提供了两种发送消息的方式。一种是实用类方法(函数调用),另一种是重新定义运算符,cin和cout就是采用这种方式。 */ return 0; }
转载请注明原文地址: https://www.6miu.com/read-84552.html

最新回复(0)