本 Wiki 开启了 HTTPS。但由于同 IP 的 Blog 也开启了 HTTPS,因此本站必须要支持 SNI 的浏览器才能浏览。为了兼容一部分浏览器,本站保留了 HTTP 作为兼容。如果您的浏览器支持 SNI,请尽量通过 HTTPS 访问本站,谢谢!
这是本文档旧的修订版!
第 1 章笔记
void
为不返回)void
,可以无形参
// int 是返回类型
// main 后的括号是形参列表(为空)
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
// pInfo 是 parameter
// test1, test2 是 argument
void fun(const char* pInfo)
{
std::cout << pInfo << std::endl;
}
// 无形参的写法
// 通常是执行逻辑中不包含变量,但为了接口需要保留该变量的形参位置
// 因此只写形参类型
void fun2(const char* pInfo, int)
{
std::cout << pInfo << std::endl;
}
int main(int argc, char const *argv[])
{
fun("test1");
fun2("test2", 1);
return 0;
}
main
是整个程序的入口,是操作系统调用 C++ 的接口int
, 0
为正常返回。没有 return
默认 main
返回 0
linux 下可以通过下面的命令检查程序的返回值(是否成功运行):
#check the return type of the program
$echo $?
int main(int argc, char* argv[]) {}
</code cpp> 定义于 iostream 中 如果使用双引号,系统会在当前目录中找 如果使用三角括号,系统会优先找库中的内容 自定义 header 通常给 .h 后缀 #include <iostream> #include “myheader.h” </code>
cin
cout
/ cerr
/ clog
cerr
可以定向到不同的文件中,作为错误的输出<code bash>main > txt1 2>txt2<code>