一、代码示例解析:

 #include <iostream>
int main()
{
using namespace std;
cout << "come up and C++ me some time.";
cout << endl;
cout << "you are right!"<<endl;
return ;
}

运行结果:

come up and C++ me some time.
you are right!

说明:这里的using namespace std 为名称空间,它是为了让编写大型程序以及将多个厂商现有的代码组合在一起,也是为了统一管理。但是如果我们不使用名称空间的话,上面代码一般是这样的:

#include <iostream>
int main()
{
//using namespace std;
std :: cout<<"come up and C++ me some time.";
std ::cout << std::endl;
std ::cout << "you are right!"<<std::endl;
return ;
}

运行结果和第一个示例是一样的,一般在做大型项目的时候会采用这种写代码风格,平时我们学习用的比较多是使用using 编译指令,也就可以使用名称空间里面已经定义好的名称了,就不用这样写代码了,就是第一个示例,这种代码风格有点偷懒,不建议这种写法。cout <<"you are right !"  ,其中“<< ”表示把这个字符串发送给cout ;endl 是一个控制符,它表示换行的意思,和换行符“\n”的作用类型,而且他也位于头文件iostream中,

注意:刚才上面的“<<”表示插入运算符,这个有点和按位左移运算符一样,但是他们的作用不同,这个就是运算符重载的概念,就是一个运输符,通过重载,将含有不同的功能描述。

接下来我们再来看一个实例:

#include <iostream>
int main()
{
using namespace std;
int carrots; cout << "how many carrots do you have ?"<< endl;
cin >> carrots;
cout<< "here you are two more.";
carrots=carrots + ;
cout << "now you have "<<carrots<<" carrots."<<endl;
return ;
}

运行结果:

how  many carrots do you have ?

here you are two more.now you have  carrots.

说明:这里我们主要来学习一下cin的使用方法,cin >>carrots,这条语句主要是把我们要输入的值赋给carrots变量,

最新文章

  1. GC
  2. 浅谈c语言的指针
  3. 作业七:团队项目——Alpha版本冲刺阶段006
  4. 拿到阿里,网易游戏,腾讯,smartx的offer的过程
  5. 问题解决——Group Box控件遮挡其他控件
  6. FZU 2092 bfs+记忆化搜索
  7. windows下安装yaf和git
  8. Timer定时器
  9. Leetcode:best_time_to_buy_and_sell_stock_II题解
  10. 1016. 部分A+B
  11. iOS 面试大全从简单到复杂(简单篇)
  12. 如何使用sourcetree 或 IDEA 自带的git合并代码?
  13. Linux系统下安装jdbc与tomcat
  14. 安卓自动化测试,贺晓聪之uiautomator设备和选择器~Python详解
  15. linux环境下tab键自动缩进4个空格
  16. CentOS 7.4 使用源码包编译安装MySQL 5.7.20
  17. python学习笔记07-元组 字典
  18. [na]icmp重定向
  19. freemarker 判断写法
  20. eclipse下的tomcat内存设置大小(转)

热门文章

  1. List集合概述和特点
  2. requests模块使用二
  3. Android 引导页的代码
  4. 微信小程序校历组件
  5. wr720n v4 折腾笔记(四):安装inode客户端njitclient
  6. CF1327D Infinite Path 题解
  7. word2vec 和 glove 模型的区别
  8. [SQL]511+512+534+550+569
  9. css清除浮动影响
  10. poj - 2096 概率dp (找bug)