c++官方文档
来自官方文档。。。感谢老王指出需要c++11,一下代码全在c++11下编译,编译参数加入 -std=c++11
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <climits>
#include <sstream>
using namespace std; int main(const int argc, char** argv)
{
//c style
int i = 0;
//c++ style
int j(1);
//only in c++ 11
int k = { 2 };
cout << i << endl;
cout << j + k << endl;
int foo = 0;
//same as int bar=foo;
auto bar = foo;
cout << bar << endl;
//bar2 type is int,has no initVal
decltype(foo) bar2;
bar2 = 4.2000;
cout << bar2 << endl;
cout << sizeof(wchar_t) << endl;
//base 10
int ii = 10;
//base 8
int kk = 010;
//base 16
int kkk = 0xff;
cout << ii << " " << kk << " " << kkk << endl;
int kkkk = 75; //int
unsigned int uik = 4294967295u; //unsigned int
long lk = 75l; //long
long ulk = 75ul; //unsigned long
cout << kkkk << " " << uik << " " << lk << " " << ulk << endl;
cout << "long double size " << sizeof(long double) << endl;
cout << "long long int size " << sizeof(long long int) << endl;
//default type for floating-point literals is double
//we can add suffix f or l
float fi = 6.02e23f; //float
long double ld = 3.14159L; //long double
cout << "fi " << fi << " long double " << ld << endl;
//Internally, computers represent characters as numerical codes
//计算机本质上将字符表示成数字
string x = "string expressed in \
two lines";
cout << x << endl;
//All the character literals and string literals described above are made of characters of type char
//所有字符和字符串字面量都是由char组成,可以加下面的前缀
//u char16_t
//U char32_t
//L wchar_t
//string字面量可以加以下前缀
//u8 The string literal is encoded in the executable using UTF-8
//执行时用utf-8编码
//R The string literal is a raw string
//表示原始的string
string ss = R"(string with \backslash)";
string sss = "(string with \backslash)";
cout << ss << endl;
cout << sss << endl;
//c++已经存在三个字面量 true false nullptr
cout << "bool" << sizeof(bool) << " sizeof nullptr" << sizeof(nullptr)
<< endl;
bool footrue = true;
bool foofalse = false;
int* p = nullptr;
cout << footrue << endl;
cout << foofalse << endl;
//&p p的地址
//*p p指向内存的内容
//p p这块内存中的值
cout << p << endl;
cout << "&p " << &p << endl;
int** pp = &p;
cout << pp << endl;
//有魔力的语法
//根据文档的描述 c++内置三个字面量 true,false nullptr
cout << (false == nullptr) << endl;
//显示转换
int ci;
float cf = 3.14;
//继承自 c
ci = (int) cf;
//c++ style
ci = int(cf);
//The value returned by sizeof is a compile-time constant, so it is always determined before program execution.
//sizeof返回编译时的常量,所以这个值永远都在执行前确定
string mystr("123465 456 79");
int myint;
//标准头文件sstream定义了一种叫做stringstream的类型,允许把string作为输入流
stringstream sin(mystr);
//流已经到末尾
string mystr2;
while (sin >> myint)
cout << myint << " ";
cout << endl;
getline(stringstream(mystr), mystr2);
cout<<mystr2<<endl;
return 0;
}
c++官方文档的更多相关文章
- 【AutoMapper官方文档】DTO与Domin Model相互转换(上)
写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...
- 2DToolkit官方文档中文版打地鼠教程(三):Sprite Collections 精灵集合
这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...
- 2DToolkit官方文档中文版打地鼠教程(二):设置摄像机
这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...
- 2DToolkit官方文档中文版打地鼠教程(一):初始设置
这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...
- 【AutoMapper官方文档】DTO与Domin Model相互转换(中)
写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...
- 【AutoMapper官方文档】DTO与Domin Model相互转换(下)
写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...
- Ionic2系列——Ionic 2 Guide 官方文档中文版
最近一直没更新博客,业余时间都在翻译Ionic2的文档.之前本来是想写一个入门,后来觉得干脆把官方文档翻译一下算了,因为官方文档就是最好的入门教程.后来越翻译越觉得这个事情确实比较费精力,不知道什么时 ...
- Kotlin开发语言文档(官方文档)-- 目录
开始阅读Kotlin官方文档.先上文档目录.有些内容还未阅读,有些目录标目翻译还需琢磨琢磨.后续再将具体内容的链接逐步加上. 文档链接:https://kotlinlang.org/docs/kotl ...
- 一起学微软Power BI系列-官方文档-入门指南(1)Power BI初步介绍
我们在前一篇文章微软新神器-Power BI,一个简单易用,还用得起的BI产品中,我们初步介绍了Power BI的基本知识.由于Power BI是去年开始微软新发布的一个产品,虽然已经可以企业级应用, ...
- 一起学微软Power BI系列-官方文档-入门指南(2)获取源数据
我们在文章: 一起学微软Power BI系列-官方文档-入门指南(1)Power BI初步介绍中,我们介绍了官方入门文档的第一章.今天继续给大家介绍官方文档中,如何获取数据源的相关内容.虽然是英文,但 ...
随机推荐
- 杭电OJ1789、南阳OJ236(贪心法)解题报告
杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...
- 多个sshkey 指定key来clone仓库
Something like this should work (suggested by orip): ssh-agent bash -c 'ssh-add /somewhere/yourkey; ...
- stenciljs 学习一 web 组件开发
stenciljs 介绍参考官方网站,或者 https://www.cnblogs.com/rongfengliang/p/9706542.html 创建项目 使用脚手架工具 npm init ste ...
- silverlight 进行本地串口调用的一种可行的解决方法
silverlight 是一个很不错的开发平台,我们可以设计出很绚丽的界面,用户可以拥有很好的体验,但是就目前来说,进行本地串口的直接调用时不行的,因为安全的原因,有没有相对简单的调用方式呢? 答案是 ...
- nyoj 幸运三角形
幸运三角形 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 话说有这么一个图形,只有两种符号组成(‘+’或者‘-’),图形的最上层有n个符号,往下个数依次减一,形成倒 ...
- Apache+modjk布置tomcat集群
一.版本: Apache: 2.2.14: 下载地址:http://archive.apache.org/dist/httpd/binaries/win32/ Mod_jk:tomcat-connec ...
- spring 核心思想:AOP 理解
什么是AOP? AOP概念介绍 所谓AOP,即Aspect orientied program,就是面向方面(切面)的编程. 面向切面编程Aspect-Orlented-Programming,即AO ...
- python版 google密码认证器
#!/usr/bin/env python # -*- coding:utf-8 -*- import hmac, base64, struct, hashlib, time def calGoogl ...
- virtualbox安装增强功能并设置共享文件夹
virtualbox安装增强功能并设置共享文件夹 我们在安装之前,必须得先安装好它所需要的依赖包,不然安装过程必定会出现错误! 一.安装依赖包 #yum install kernel-headers# ...
- python 正则表达式的使用
本文以例子的形势,介绍如何在python中使用正则表达式. Example1 #!/usr/bin/python import re import sys pattern = re.compile(r ...