C++ Tutorial Lesson 1

C++ is a language, like Chinese, English, Russian, etc., and now we have to learn this language.

Give you a primary program to learn how to get started with C++.

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

After the Dev C++ software is running (F11 key), it will look like this:

Each sentence of c++ is connected with a semicolon (please adjust the input method to English).

The explanation is as follows:

注:"//"在c++里是注释的意思
#include<iostream>   //#:在运行前就准备好的。  include:包含。  <>:一个工具箱,你可以理解为你出去野餐,要带上捕鱼、望天象、吃饭、睡觉的东西,不能把它们乱放,每一种都要放在一个工具箱,这就是一个工具箱,以后会学更多,当然还有万能工具箱。iostream:i:in  o:out  stream:流。  句意为包含输入输出流工具箱。有了这个工具箱,就可以输入输出了。
using namespace std;  //使用标准名字空间(std:standard),有了这句话,程序就能正常运行了。
int main() {  //int:integer在这里是指函数。main:主要,()表示一种函数。{}是连接开始和结束的符号,句意为主函数开始。
	cout<<"Hello, world!";  //cout可以理解为c++out即c++系统输出,<<表示流(即第一行的stream),“”表示输出字符,若没有“”系统会报错。句意为输出“Hello,world!”。
	return 0;  //句意为主函数结束,返回0。即表示程序结束。
}

Practice is here!

Please write a program that outputs "I love IT", and the answer will be announced later.

The answer is as follows:

#include<iostream> 
using namespace std;
int main() {
	cout<<"I love IT";
	return 0;
}

Are you doing it right?


new line

If Xiao Ming wants to output

3

4

How to do it?

#include<iostream> 
using namespace std;
int main() {
	cout<<"3";
    cout<<"4";
	return 0;
}
对吗?
#include<iostream> 
using namespace std;
int main() {
	cout<<"3
4";
	return 0;
}
对吗?

Obviously they are all wrong, the first one will output 34, and the second one will report an error.

Actually the answer is as follows:

#include<iostream> 
using namespace std;
int main() {
	cout<<"3"<<endl;
    cout<<"4";  //注:输出数字可以省略“”。
	return 0;
}

endl is the end line, which is a newline.

Mengxin (if not, don't watch it), listen to it, and go home homework to output "Very Good" "" "" "and Digital 233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 (There will be a bug) The answer to the second lesson is revealed! You can find the difficulty submission questions that suit you on the Kuaikuai Programming website ( https://www.kkcoding.net/ ) (please submit questions 1721, 1722, 3, 284, 1015)

Guess you like

Origin blog.csdn.net/Djyt4102520/article/details/124173100