c++使用
幻想之渔
永远相信美好的事情即将发生!
展开
-
Linux C++获取系统名称和ip
使用封装的这个函数获取系统的名称和ip。#include /* cout */#include /* gethostname */#include /* struct hostent */#include /* inet_ntop */bool GetHostInfo(std::string& hostName, std::string& Ip) { char name[25原创 2017-12-26 11:40:22 · 8053 阅读 · 9 评论 -
C++获取当前时间字符串
#include std::string GetNowTime() { time_t setTime; time(&setTime); tm* ptm = localtime(&setTime); std::string time = std::to_string(ptm->tm_year + 1900) + "/"原创 2017-12-29 12:25:42 · 4718 阅读 · 1 评论 -
C++中 =defaule 和 =delete 使用
编译器默认为一个类生成的默认函数默认构造函数默认析构函数默认拷贝构造函数默认赋值函数移动构造函数移动拷贝函数class DataOnly {public: DataOnly () // default constructor ~DataOnly () // destructor ...原创 2018-04-22 01:24:42 · 34225 阅读 · 3 评论 -
C/C++程序中获取变量的名称
C/C++变量名称的获取原创 2018-04-18 17:29:54 · 12245 阅读 · 1 评论 -
代码整洁之道
有意义的命名避免误导做有意义的区分使用读的出来的名称避免使用编码避免思维映射类名:类名和对象名应该是名词或名词短语,不应当是动词。避免使用Manager、Processor、Data或Info这样的类名。方法名:方法名应当是动词或动词短语,别扮可爱:如果名称太耍宝,那就只有同作者一般有幽默感的人才能记得住。每个概念对应一个词别用双管词使用解决方案领域名词使用源自所涉问题领域的原创 2018-04-23 19:19:07 · 217 阅读 · 0 评论 -
谈谈const
const member functions (常量成员函数) 告诉编译器,该成员函数不能改变类的成员变量 项目 const object(常量对象 data members不能改变) non-const object(非常量对象 data members可以改变) const member functions(保证不更改data members) ye...原创 2018-04-21 21:27:12 · 208 阅读 · 0 评论 -
C++版本比较函数
int VersionCompare(string v1, string v2) { uint32_t vnum1 = 0; uint32_t vnum2 = 0; for (int i = 0,j = 0; (i < v1.length() || j < v2.length()); ) { while (i < v1.length() &...原创 2018-12-27 13:53:51 · 617 阅读 · 0 评论 -
如何让一个C++函数不抛出异常
1. 尝试一如果一个fun()调用funA(),funA()可能会抛出异常,那么想让fun()不抛出异常,fun()就得catch funA()的所有异常,并且不要继续往上throw。#include <iostream>using namespace std;int funA(int a) { std::cout << "funA : " << a...原创 2019-03-29 13:43:43 · 1941 阅读 · 0 评论