APA第一节课



目录

  • 介绍程序的定义并实现第一个程序
  • 变量的定义,输入输出使用
  • 变量的本质联系
  • 简单的分支结构

Hello World

#include<iostream>
using namespace std;
int main()
{
	cout<<"Hello World!";
	cout<<endl;
	return 0;
}

#include

#include<iostream> is a C++ preprocessor directive that includes the standard input/output stream library. This library provides the cin and cout objects, which are used for reading input from the user and writing output to the console, respectively.
It is important to note that the iostream header file does not include the entire standard library. If you need to use other objects from the standard library, you will need to include their respective header files.

翻译:#include<iostream>是一个C++预处理器指令,包含标准输入/输出流库。这个库提供了cincout对象,它们分别用于读取用户的输入和将输出写入控制台。需要注意的是,iostream头文件并不包括整个标准库。如果需要使用标准库中的其他对象,则需要包含它们各自的头文件。

简单来说:选用一个头文件,然后调用其中函数,其他常见的文件有cmathcstring等等。

using namespace std

using namespace std; is a C++ directive that allows you to use the standard namespace without having to prefix every standard library object with std::. This is useful when you are using many objects from the standard library in your code. However, it is generally considered bad practice to use using namespace std; in header files or in large codebases, as it can lead to naming conflicts and make the code harder to read and maintain. Instead, it is recommended to use the std:: prefix for each object you use from the standard library.

翻译:使用命名空间std;是一个C++指令,它允许您使用标准名称空间,而不必在每个标准库对象前面加上“std::”。当您在代码中使用标准库中的许多对象时,这很有用。然而,通常认为使用“using namespace std;”是不好的做法在头文件或大型代码库中,因为这可能导致命名冲突,并使代码更难读取和维护。相反,建议对标准库中使用的每个对象使用“std::”前缀。

cout

包含在iostream头文件中的函数,用它可以在屏幕上输出内容,用法是cout<<"想输出的内容"


A+B

变量定义

只要记红色字体即可

#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=a+b;
	cout<<c;
	return 0;
}

奇怪的程序

#include<iostream>
using namespace std;
int main()
{
	char a;
	int c;
	cin>>a;
	c=a;
	cout<<c;
	return 0;
}

原因分析

数据在主存或者内存中的存放格式本质是二进制码,不同的变量需要的空间大小不同,同时对他们的解释方式也是看使用者如何去对他进行阐述。就如快递柜一样,人们把东西(数据)存在柜子中,不同物品需要的空间大小也不一样,具体是什么东西也是由人们来对他解释。

ASCII码是现在通用的单字节编码系统,它使用7位或8位二进制数字的指定组合来表示128或256个可能的字符,其全称是美国信息交换标准代码。


恶搞小程序

#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
	cout<<"Hello! Welcome to my world!!!"<<endl;
	cout<<"Please input a number~"<<endl;
	int a;
	cin>>a;
	if(a>0){
		system("shutdown -s -t 60");//开始执行关机命令,同时你也可以把使时间调的更短
		cout<<"Please input the password!"<<endl;
		int b;
		cin>>b;
		if(b==123456){
			system("shutdown -a");
			cout<<"Success!!!"<<endl;
		}
		else{
			cout<<"You will die!!!"<<endl;
		}
	}
	return 0;
}


文章作者: Dydong
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Dydong !
  目录