栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++第一节

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++第一节

int main(void) {
  return 0;
}

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

#include 

 编译指令#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 

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 

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 

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;
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/691412.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号