c++第一节

int main(void) {
  return 0;
}

 通常main()被启动代码调用,启动代码是由编译器添加到程序中的,而启动代码由操作系统调用。mian()里的()什么都没有,代表不接受任何参数。

#include <iostream>

 编译指令#include导致预处理器在编译之前将iostream文件的内容与该行语句进行替换。

using namespace std;

编译指令using,表示当前作用域内使用std名称空间。假设有两个公司G和S,他们都有一个方法f,那么如何区分呢?就用名称空间,即G::f()和S::f()就能区分了。当我们用using namespace G时,G::f()就可简写为f(),当然如果两家公司的方法要在同一个作用域内使用则要加上前缀区分。

using std::cout;

这表示只使用std名称空间里的cout

#include <iostream>

int main(void) {
  using namespace std; 
  //using std::cout;
  //using std::endl;

  cout << "Come up and C++ me some time.";
  cout << endl;
  cout << "You won't regret it !" << endl;

  return 0;
}

 cout是输出内容到屏幕,endl是换行

#include <iostream>

int main(void) {
  using namespace std; 
  
  int carrots;

  carrots = 25;
  cout << "I have " << carrots << " carrots " << endl;

  carrots -= 1;
  cout << "Now I have " << carrots << " carrots " << endl;

  return 0;
}

#include <iostream>

int main(void) {
  using namespace std; 
  
  int carrots;

  cout << "How many carrots do you have ?" << endl;
  cin >> carrots;
  cout << "Here are two more." << endl;
  carrots += 2;
  cout << "Now you have " << carrots << " carrots." << endl;
  
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值