
C++
Mos_x
大一软工,迈向合格程序员之路(7年过去了,确实是程序员了
展开
-
二进制的一些
(1)取出一个数二进制中的最后一个1:int lowbit(int n){return n&-n; //n与-n做与运算}原创 2017-03-31 20:37:41 · 332 阅读 · 0 评论 -
strtok解析字符串
char *strtok(char s[], const char *delim);首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。原创 2016-06-22 16:41:27 · 355 阅读 · 0 评论 -
(C++)虚析构函数
基类:Per继承类:Stu主函数:Per *p = new Stu;delete p;如果 ~Per() //析构函数没有声明为虚函数则不会调用Stu类的析构函数,只调用~Per()如果 vritual ~Per() //虚析构函数则也会调用Stu类的析构函数。原创 2016-06-01 18:21:49 · 317 阅读 · 0 评论 -
(C++)int,char,string之间的一些转换
#include#include#includeusing namespace std;int main(){ //string→char string str= "asd"; printf("%s\n", str.c_str()); // 就是 str.c_str() //char→string char ch[] = "qwe"; str = ch;原创 2016-05-23 18:48:04 · 456 阅读 · 0 评论 -
(C++)多重继承
#include#includeusing namespace std;class data{protected: char *name;public: data(char *name); data(); ~data();};class teacher :protected data{protected: int sal;public: teacher(cha原创 2016-03-16 18:29:48 · 281 阅读 · 0 评论 -
(C++)保留小数点位数
需要 iomanip 头文件,在cout后面添加例:#include#include #includeusing namespace std;const double P = 3.1415926;int main(){ double r, c, s; cin >> r; //输入半径 c = 2 * P*r; //计算周长 s =原创 2016-03-02 23:22:27 · 2379 阅读 · 0 评论