• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c++官方文档

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  来自官方文档。。。感谢老王指出需要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;
}

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C语言计算任意数的任意次方发布时间:2022-07-18
下一篇:
C#中将long浮点数格式化为{H:min:s.ms}格式的字符串的方法发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap