
標準程式庫還有很多應用,例如地區資訊程式庫 (localizations library)
| 名稱 | 功能 |
|---|---|
| <locale> | 地區性工具。 |
| <clocale> | C 語言地區性工具。 |
| <codecvt>C++11 | Unicode 轉換工具。 |
正規表示式程式庫 (regular expression library)
| 名稱 | 功能 |
|---|---|
| <regex>C++11 | 正規表示式工具。 |
原子作業程式庫 (atomic operations library)
| 名稱 | 功能 |
|---|---|
| <atomic>C++11 | 原子作業工具。 |
執行緒程式庫 (thread support library)
| 名稱 | 功能 |
|---|---|
| <thread>C++11 | std::thread |
| <mutex>C++11 | std::mutex |
| <shared_mutex>C++14 | std::shared_timed_mutex |
| <future>C++11 | std::future |
| <condition_variable>C++11 | std::condition_variable |
以及其他 C 語言相容的程式庫等等
| 名稱 | 功能 |
|---|---|
| <ciso646> | C 語言的 iso646.h 。 |
| <ccomplex>C++11 | C 語言的 complex.h 。 |
| <ctgmath>C++11 | C 語言的 tgmath.h 。 |
| <cstdalign>C++11 | C 語言的 stdalign.h 。 |
| <cstdbool>C++11 | C 語言的 stdbool.h 。 |
舉一例如下
| 001 | #include <iostream> |
| 002 | #include <string> |
| 003 | #include <regex> |
| 004 | |
| 005 | using namespace std; |
| 006 | |
| 007 | int main() { |
| 008 | string s1 = "Hello world!"; |
| 009 | cout << s1 |
| 010 | << endl; |
| 011 | |
| 012 | regex r("Hello"); |
| 013 | string t = "Goodbye"; |
| 014 | string s2 = regex_replace(s1, r, t); |
| 015 | |
| 016 | cout << s2 |
| 017 | << endl; |
| 018 | |
| 019 | } |
| 020 | |
| 021 | /* Kaiching Chang |
| 022 | u1507.cpp |
| 023 | 2014-02 */ |
此例示範 regex 中正規表示式 (regular expression) 的應用,因此要先 #include <regex>
| 003 | #include <regex> |
這裡先建立 regex 型態的物件,然後利用 regex_replace() 把 "Hello" 換成 "Goobye"
| 012 | regex r("Hello"); |
| 013 | string t = "Goodbye"; |
| 014 | string s2 = regex_replace(s1, r, t); |
編譯執行,結果如下
| $ g++ u1507.cpp -std=c++0x |
| $ ./a.out |
| Hello world! |
| Goodbye world! |
| $ |
continue ...
沒有留言:
張貼留言