
- C標準庫
- C標準庫
- C++標準庫
- C++庫 - 首頁
- C++庫 - <fstream>
- C++庫 - <iomanip>
- C++庫 - <ios>
- C++庫 - <iosfwd>
- C++庫 - <iostream>
- C++庫 - <istream>
- C++庫 - <ostream>
- C++庫 - <sstream>
- C++庫 - <streambuf>
- C++庫 - <atomic>
- C++庫 - <complex>
- C++庫 - <exception>
- C++庫 - <functional>
- C++庫 - <limits>
- C++庫 - <locale>
- C++庫 - <memory>
- C++庫 - <new>
- C++庫 - <numeric>
- C++庫 - <regex>
- C++庫 - <stdexcept>
- C++庫 - <string>
- C++庫 - <thread>
- C++庫 - <tuple>
- C++庫 - <typeinfo>
- C++庫 - <utility>
- C++庫 - <valarray>
- C++ STL庫
- C++庫 - <array>
- C++庫 - <bitset>
- C++庫 - <deque>
- C++庫 - <forward_list>
- C++庫 - <list>
- C++庫 - <map>
- C++庫 - <multimap>
- C++庫 - <queue>
- C++庫 - <priority_queue>
- C++庫 - <set>
- C++庫 - <stack>
- C++庫 - <unordered_map>
- C++庫 - <unordered_set>
- C++庫 - <vector>
- C++庫 - <algorithm>
- C++庫 - <iterator>
- C++高階庫
- C++庫 - <any>
- C++庫 - <barrier>
- C++庫 - <bit>
- C++庫 - <chrono>
- C++庫 - <cinttypes>
- C++庫 - <clocale>
- C++庫 - <condition_variable>
- C++庫 - <coroutine>
- C++庫 - <cstdlib>
- C++庫 - <cstring>
- C++庫 - <cuchar>
- C++庫 - <charconv>
- C++庫 - <cfenv>
- C++庫 - <cmath>
- C++庫 - <ccomplex>
- C++庫 - <expected>
- C++庫 - <format>
- C++庫 - <future>
- C++庫 - <flat_set>
- C++庫 - <flat_map>
- C++庫 - <filesystem>
- C++庫 - <generator>
- C++庫 - <initializer_list>
- C++庫 - <latch>
- C++庫 - <memory_resource>
- C++庫 - <mutex>
- C++庫 - <mdspan>
- C++庫 - <optional>
- C++庫 - <print>
- C++庫 - <ratio>
- C++庫 - <scoped_allocator>
- C++庫 - <semaphore>
- C++庫 - <source_location>
- C++庫 - <span>
- C++庫 - <spanstream>
- C++庫 - <stacktrace>
- C++庫 - <stop_token>
- C++庫 - <syncstream>
- C++庫 - <system_error>
- C++庫 - <string_view>
- C++庫 - <stdatomic>
- C++庫 - <variant>
- C++ STL庫速查表
- C++ STL - 速查表
C++流緩衝區::getloc()函式
std::streambuf::getloc() 函式用於檢索與流緩衝區關聯的當前區域設定。區域設定包括各種方面,例如數字格式、字元分類等等,這些方面會影響流如何處理資料。
語法
以下是 std::tuple:: 的語法。(此處應為std::streambuf::getloc()的語法)
locale getloc() const;
引數
它不接受任何引數。
返回值
此函式返回當前與流緩衝區關聯的區域設定物件。
異常
如果丟擲異常,流緩衝區不會發生任何更改。
資料競爭
它訪問流緩衝區物件。
示例1
在下面的示例中,我們將考慮getloc()函式的基本用法。(此處應補充示例程式碼)
#include <iostream> #include <sstream> #include <locale> int main() { std::stringstream a; std::locale b = a.rdbuf() -> getloc(); std::cout << "Default locale: " << b.name() << std::endl; return 0; }
輸出
上述程式碼的輸出如下:(此處應補充輸出結果)
Default locale: C
示例2
考慮下面的示例,我們將結合使用imbu()和getloc()函式。(此處應補充示例程式碼)
#include <iostream> #include <sstream> #include <locale> int main() { std::stringstream a; std::locale b("en_US.UTF-8"); a.imbue(b); std::locale x = a.rdbuf() -> getloc(); std::cout << "Current locale: " << x.name() << std::endl; return 0; }
輸出
上述程式碼的輸出如下:(此處應補充輸出結果)
Current locale: en_US.UTF-8
示例3
讓我們看看下面的示例,我們將把stringstream的區域設定設定為fr_FR.UTF-8並應用getloc()函式。(此處應補充示例程式碼)
#include <iostream> #include <sstream> #include <locale> int main() { std::stringstream a; a.imbue(std::locale("fr_FR.UTF-8")); std::locale b = a.rdbuf() -> getloc(); std::cout << "Locale: " << b.name() << std::endl; a << 1123228.33; std::cout << "Formatted number: " << a.str() << std::endl; return 0; }
輸出
如果我們執行上述程式碼,它將生成以下輸出:(此處應補充輸出結果)
Locale: fr_FR.UTF-8 Formatted number: 1 123 228,33
streambuf.htm
廣告