endl 换行
endl 换行
ctrl+k ctrl+c
ctrl+k ctrl+u
数组
跑
填减注释
添加:Ctrl+k Ctrl+c
减少:Ctrl+k Ctrl+u
auto关键字和练习题
自动推断类型,一般我们定义一个变量的时候是要指定它的类型,通过auto关键字可以不用指定它的类型
auto a = ' a ' ;
cout << a << endl ;
auto b = 100 ;
cout << b << endl ;
变量等于 类型 名字 = 初始值
一行行的称为语句
#include <iostream> 预处理指令
include(引用作用)引入iostream 输入输出流
一般引入都是头文件 header.h
.h结尾都是头文件
把一行字符串在控制台打印出来,叫输出
接收用户的字符串,叫输入
cout属于iostream
引入系统内置的使用<>,自己创建的使用“”并且要加上.h
iostream下面有不同的功能、不同的函数,每个函数属于不同的命名空间,通过命名空间进行分类iostream-namespace std-cout
在把using namespace std; 注释后,可直接在cout前加上std::cout也可以使用,因为cout在std里面
也可以using std::cout;
三种写法
1.注释(绿色部分)
2.语句就是一行代码 ,以分号结束
把语句当成一个命令
void LearnCppTest::getDateTime() { long time; cout << "请输入秒:" ; cin >> time; if(!(long)time){ cout << "请输入正确的格式:" << time << endl; return; } cout << "你输入的秒数为:" << time << endl; long d = time/(60*60*24); long h = (time%(60*60*24)) / (60*60); long m = ((time%(60*60*24)) % (60*60)) / 60; long s = ((time%(60*60*24)) % (60*60)) % 60; cout << d << "天" << h << "小时" << m << "分钟" << s<< "秒" << endl; }
变量名不可以重复
变量名不可以使用关键字
变量名不能空格,只能用下划线
cin>>(用户输出)
右键,启动项目,可以设置项目为启动项目
cout 是输出
cout<< " "; 输出语句
cout<<endl 换行
cout<<"你好"<<endl #输出完换行
"\n"换行,可以放在字符创
"endl"单独放在字符串
另一个输出指令
printf("我的年龄是%s"#会把他放在后面的,"18")
printf("wdnls%d",18)
需要英文输入法输入命令
#include "stdafx.h"
#include <iostream>
int main()
{
using namespace std;
cout <<"你好";
cout <<endl;
cout <<"我开始学程序";
return 0;
}
开始调试会自动关闭
开始执行不执行
cout用作是输出
格式cout << "";
main函数,入口函数
return 0;返回
int main()
{
return 0;
}
一条语句可以看做是一个命令
语句都以 ; 结束
#include预处理指令
<iostream>输入输出流
引入系统内置的文件<>
引入自己创建的文件""
using 使用
namesppace 命名空间 对函数进行分类
如不使用命名空间,在函数前(cout)需要加上std::
【using nameespace std;(引入所有std,比较偷懒,代码多容易出错)】
【更加严谨的写法,不容易出错,但是略麻烦using std ::cout;
using std ::endl;
using std ::cin;】
main函数
#include <iostream>
int main()
#include 预处理指令,yingur