
c++
半片瓜
我要每天充实且快乐
展开
-
C++数学函数
#include #include using namespace std;int main(){ double a=3; cout<<abs(a)<<endl; //绝对值 cout<<pow(a,3)<<endl; //冥 cout<<exp(3)<<endl; //指数 cout<<sqrt(a)<<endl; //开平方 cout<<log(a)<<endl; /转载 2015-04-07 11:00:31 · 346 阅读 · 0 评论 -
使用printf打印不出信息
许多新人干刚学习C语言的时候,使用printf发现打印不出自己原创 2015-11-15 14:06:37 · 4153 阅读 · 0 评论 -
算术运算符重载后的总结
重载是为处理自定义类型的操作#include class Overload{private: int a; int b; friend ostream& operator<<(ostream &out, Overload &one);public: Overload(int a = 0, int b = 0) { this->a = a; this->b = b;转载 2015-02-15 22:03:38 · 327 阅读 · 0 评论 -
C语言数据类型范围
此次测试是在ubuntu下对于C语言数据类型sizeofchar 1个字节short 2个字节int 4个字节long 4个字节float 4个字节double 8个字节一.char的范围char有8位,其中一位为符号位,2^7=128,其取值范围为-128~127,其中0~127位对应ASCII码表,负数位对应各行业各自设置。原创 2015-11-03 19:26:54 · 942 阅读 · 0 评论 -
C++的字符串
string类方法汇总构造函数 产生或复制字符串析构函数 销毁字符串=、assign 赋予新值swap 交换字符串+=、append()、push_bash() 添加字符insert() 插入字符erase() 删除字符clear() 移除全部字符resize() 改变字符数目replace() 替换字符size()、length() 返回字符数目m原创 2015-04-06 12:36:03 · 347 阅读 · 0 评论 -
C++强制类型转换
c语言类型转换时不报错c++会报错因为c++强语言C++提供4种方式:static_cast(数据)用于数值类型之间以及void*和别的*类型之间reinterpret_cast(数据)用于数值类型与地址类型之间或地址相互之间const_cast(T常量的地址)去掉对地址所指向的目标的const限制。dynamic_cast#includeusing namesp转载 2015-04-04 10:07:40 · 365 阅读 · 0 评论 -
c++ Vector
使用vector必须添加头文件:#include由于vector属于std命名域需添加using std ::vector;vector in;或std::vector in使用全局域可以省去很多麻烦using namespace std;Vector成员函数函数 表述转载 2015-04-06 15:08:25 · 338 阅读 · 0 评论 -
fseek的使用
下面例子每次偏移一个字符长度#include int main(int argc, char* argv[]){ int i; FILE *fp; //fp == 12345678901234567890 if(argc <= 1) { printf("please input paracter\n"); return 1; } if((fp = fopen(arg原创 2015-04-16 09:29:09 · 234 阅读 · 0 评论 -
输出转换字符
整形转换d,i 打印整数为有符号的十进制o 打印整数为无符号的八进制u打印整数为无符号的十进制x,X打印整数为无符号的十六进制浮点转换f 打印正常浮点数,默认6位小数点e,E 打印字符按指数形式显示g,G 用定点形式或指数形式打印浮点型其他转换c 单个字符s 字符串p 字符串转换说明转载 2015-04-16 20:26:06 · 404 阅读 · 0 评论 -
十进制转十六进制
#include using namespace std;int main(){ int n = 30; char s[10000]; int k = 0; while(n!=0) { if(n % 16 >= 10) { s[k++] = 'A'+n%16 - 10; } else { s[k++] = '0' + n%16; } n/=16转载 2015-04-07 09:58:16 · 339 阅读 · 0 评论 -
c++读写
这是大神们的总结ios::in为输入(读)而打开文件ios::out为输出(写)而打开文件ios::ate初始位置:文件尾ios::app所有输出附加在文件末尾ios::trunc如果文件已存在则先删除该文件ios::binary二进制方式fstream类转载 2015-04-04 23:16:03 · 291 阅读 · 0 评论 -
关于对有一级指针,二级指针的初始化及其浅拷贝和深拷贝
#include "iostream"using namespace std;class test{ public: int a; char name[64]; char* b; char** c; };//指针初始化 test* create() { test *p = (test *)malloc(sizeof(test )); memset(p, 0, s原创 2015-02-16 15:45:40 · 1867 阅读 · 0 评论 -
C++可变长不确定类型的参数
#include "stdafx.h"#include #include #include "iostream"using namespace std;typedef struct Params { enum ParamsType{NILL ,INT,CHAR, CHARS, DBL}; ParamsType type; union {原创 2016-04-21 19:38:28 · 1600 阅读 · 0 评论