This is the first repository I created in C++. I have been writing programs in C language for years. Some of them are even written with cpp extension. But I have never used some C++ features. So in this repo, I would like to show you some examples of C++ STL.
You should prepare all the libraries needed in order to generate Makefiles
- vectordemo: A demonstration of
std::vector. It's something similar to an array. But it contains more methods. It simply prints out everything inside the array. - regexdemo: A demonstration of POSIX BRE written in C language using libgnurx because I can't use the standard C++11's regex library in MinGW.
- posixeredemo: A demonstration of POSIX ERE which stands for Extended Regular Expression, written in C language too. I recently discovered that the only difference is to add REG_EXTENDED in
cflags. - globalctors: A demonstration of GCC Global Constructor: A function that is automatically called before main.
- cpudemo: A x86-specific demonstration of getting CPU information using
cpuid
- factor: This helps you factor any expressions that is in ax2+bx+c format. Following is the possible output
main: enter coefficient for: ax^2+bx+c a=12 b=-7 c=-12 main: Processing 12x^2-7x-12... (3x-4)(4x+3) - squareroot: Re-implementation of sqrt() It uses the following steps to get the possible accurate value:
- Guess a value called G
- Check if G is close enough to the input/G
- Return G if true, otherwise goto 1
- binarysearch: An implementation of searching node in an array with least comparisons.
- bitfield: A program that shows the value of struct with bitfield in the memory
struct{ char a:1; char b:1; char c:1; char d:2; } bitfield; - structdemo: A program that shows difference between packed struct and default (aligned) struct.
- libvoid: A set of functions that demonstrates generic type
void*.
| Function Prototypes | Description |
|---|---|
| void swap(void* ap,void* bp,size_t sz) | Switch the values between two generic pointers. |
| void* lsearch(void* key,void* base,size_t n,size_t each) | Search stuff from an unknown type array and returns the address of the result. |
| void* lsearchx(void* key,void* base,size_t n,size_t each,cmpfunc cmp) | Same as lsearch, but with a custom function for comparing values |
- swapdemo: Demonstration of swap().
- searchdemo: Demonstration of lsearch().
- customcmpsearch: Demonstration of lsearchx().
- ipaddr: A tool to get IP address from your machine
- ftpdemo: Demonstration of FTP Protocol
Compile with
-DVERBOSEhelps show the response from server
- man_regex.txt: regular expression manual from Linux. I got function prototypes here.