#include<boost/regex.hpp>#include<iostream>#include<string>intmain(){std::strings="Boost Libraries";boost::regexexpr{"\\w+\\s\\w+"};if(boost::regex_match(s,expr)){std::cout<<"String matches the regular expression."<<std::endl;}return0;}
3. 文件系统(Filesystem)
Boost.Filesystem 提供了跨平台的文件系统操作功能,如路径操作、文件读取和写入等。
1
2
3
4
5
6
7
8
9
10
11
12
#include<boost/filesystem.hpp>#include<iostream>intmain(){boost::filesystem::pathp{"example.txt"};if(boost::filesystem::exists(p)){std::cout<<"File exists."<<std::endl;}else{std::cout<<"File does not exist."<<std::endl;}return0;}
4. 线程(Thread)
Boost.Thread 提供了多线程编程的支持,包括线程管理、互斥锁、条件变量等。
1
2
3
4
5
6
7
8
9
10
11
12
#include<boost/thread.hpp>#include<iostream>voidthreadFunction(){std::cout<<"Hello from thread!"<<std::endl;}intmain(){boost::threadt{threadFunction};t.join();return0;}