
C/C++
zoot
2017年我开始了csdn,我从互联而来,为互联而去.修行靠个人,记录.
展开
-
C/C++ 命令参数解析
exp1main.cpp#include <stdio.h>#include <stdlib.h>#include "argsh.h"int main(int argc, char* argv[]){ int tmp = 4; while( (tmp = getopt(argc, argv, "abck")) != -1 ) { printf("00000000\n"); printf("tmp=%.原创 2020-10-23 16:08:44 · 377 阅读 · 0 评论 -
C/C++ std::function
#include <iostream>#include <functional>#include <memory>class classA{ typedef std::function<void(int i)> callback_t; public: classA() {} ~classA() {} void handle(int i) { std::cout << "classA::handle " &l原创 2020-09-24 15:31:34 · 229 阅读 · 0 评论 -
C/C++ 结构体
#include <iostream>struct LogMessageEnvelope{ enum Severity{ kAssertFailed = -3, kError = -2, kWarning = -1, kInfo = 0 }; int severity;};int A(LogMessageEnvelope::Severity severity){ std::cout <原创 2020-08-26 14:46:52 · 265 阅读 · 0 评论 -
C/C++ value_type
#include <iostream>#include <vector>using namespace std;template<typename T>typename T::value_type top(const T &c){ if (!c.empty()){ return c.back(); } else return typename T::value_type();}int mai原创 2020-08-14 09:47:43 · 1234 阅读 · 0 评论 -
std::sort
#include<iostream>#include<vector>#include<algorithm>struct PathTrie{ int score; char character; int id;}*aa,*bb,*cc,*dd;bool prefix_compare(const PathTrie *x, const PathTrie *y) { if (x->score == y-&原创 2020-07-22 11:00:51 · 162 阅读 · 0 评论 -
C/C++ fscanf
testscanf.cc#include <stdio.h>#include <stdlib.h>#include <inttypes.h>int main(int argc,const char *argv[]) { char buffer[101]; uint64_t count; FILE *file = fopen("1.txt","r"); for(int i=0;!feof(file);++i){ i.原创 2020-07-07 16:08:38 · 1038 阅读 · 0 评论 -
C/C++ 项目分析
#include <sys/stat.h>#include <dirent.h>#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct { const char *name; const char *languages; ...原创 2020-02-23 14:30:30 · 447 阅读 · 0 评论 -
C/C++:GCC/G++ -Wl,-soname
mymath.h:#ifndef _MYMATH_H#define _MYMATH_Hint add(int, int);int sub(int, int);int mul(int, int);int div(int, int);#endifmymath.c:#include "mymath.h"int add(int a, int b){ retur...原创 2019-12-25 10:33:32 · 224 阅读 · 0 评论 -
C/C++ 时间处理
#include <ctime>#include <string>#include <iostream>std::string get_greet(const std::string& who) { return "Hello " + who;}void print_localtime() { std::time_t result ...原创 2019-09-26 08:59:34 · 239 阅读 · 0 评论 -
C/C++ std::map和std::pair
#include<stdio.h>#include<map>using namespace std;typedef map<int,char*> Container;typedef pair<int,char *> Element;int main(){ Container container; for (int nIn...原创 2019-09-12 15:47:17 · 3671 阅读 · 0 评论 -
kenlm
入门使用例1:使用编译好的kenlm工具手动生成file.arpa,然后测试如下代码#include "lm/model.hh"#include <iostream>#include <string>int main() { using namespace lm::ngram; Model model("file.arpa"); State state...原创 2019-09-09 17:17:19 · 397 阅读 · 0 评论 -
C/C++ std::move和std::forword关键字
#include <iostream>#include <type_traits>#include <typeinfo>#include <memory>using namespace std;struct A{ A(int&& n) { cout << "rvalue ove...原创 2019-09-04 16:02:58 · 502 阅读 · 0 评论 -
C/C++ operator关键字
#include <iostream>using namespace std;class Matrix{ float *data;public: size_t n,m; Matrix(size_t r,size_t c):data(new float[r*c]),n(r),m(c){} ~Matrix() {delete[] data;} ...原创 2019-08-13 14:52:26 · 261 阅读 · 0 评论 -
C/C++虚函数和纯虚函
虚函数和纯虚函#include <iostream>using namespace std;class A{public: virtual void out1()=0; ///由子类实现 virtual ~A(){}; virtual void out2() ///默认实现 { cout<<"A(out2)"&l...原创 2019-08-09 17:52:42 · 232 阅读 · 0 评论 -
C/C++ 左值与右值
左值、左值引用、右值、右值引用左值和右值的概念左值是可以放在赋值号左边可以被赋值的值;左值必须要在内存中有实体;右值当在赋值号右边取出值赋给其他变量的值;右值可以在内存也可以在CPU寄存器。一个对象被用作右值时,使用的是它的内容(值),被当作左值时,使用的是它的地址。引用引用是C++语法做的优化,引用的本质还是靠指针来实现的。引用相当于变量的别名。引用可以改变指针的指向...原创 2019-08-14 11:28:30 · 126 阅读 · 0 评论 -
C/C++ 测试
test_01.cpp#include <gtest/gtest.h>#include <stdio.h>using testing::Types;template <class T>class TypeTest : public testing::Test {public: bool CheckData() { if (ty...原创 2019-08-11 19:35:55 · 227 阅读 · 0 评论 -
C/C++ sstream和fstream
ostringstream#include <string>#include <iostream>#include <sstream>using namespace std;int main(){ ostringstream ostr1; ostr1 << "123" << endl;//换行也加入 ...原创 2019-08-20 17:15:58 · 392 阅读 · 0 评论 -
C/C++模版编程
1class TestBase{public: virtual ~TestBase() {} virtual void FuncA(int param) = 0; virtual bool FuncB(int param) = 0;}; template<typename T>class TestA: public TestBase{pub...原创 2019-08-12 11:47:33 · 251 阅读 · 0 评论 -
C/C++编译
sample2.cpp#include "sample2.h"#include <string.h>//克隆一个0-terminated C string, 用new分配内存.const char* MyString::CloneCString(const char* a_c_string) { if (a_c_string == NULL) return NUL...原创 2019-08-12 12:10:58 · 135 阅读 · 0 评论 -
C/C++ 异步调用
#include <future>#include <iostream>#include <string>std::string helloFunction(const std::string& s) { return "Hello C++11 from " + s + ".";}class HelloFunctionObject ...原创 2019-08-12 14:37:27 · 2128 阅读 · 1 评论 -
C/C++ 可变参数模版(variadic templates)
#include <iostream>using namespace std;template <typename T, typename ... ARGS>unique_ptr<T> factory(const ARGS&... args){ return unique_ptr<T>(new T { args... });...原创 2019-09-04 14:41:19 · 156 阅读 · 0 评论 -
C/C++宏定义
#include<stdio.h> #include <cassert>#include <iostream>#include <string>#define DEBUG_PRINT(msg) do{printf("%s - %s - line:%d, file:%s", __DATE__, __TIME__, __LINE__, __...原创 2019-07-10 18:36:39 · 543 阅读 · 0 评论