
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <multimap>
- C++ Library - <queue>
- C++ Library - <priority_queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- The C++ Advanced Library
- C++ Library - <any>
- C++ Library - <barrier>
- C++ Library - <bit>
- C++ Library - <chrono>
- C++ Library - <cinttypes>
- C++ Library - <clocale>
- C++ Library - <condition_variable>
- C++ Library - <coroutine>
- C++ Library - <cstdlib>
- C++ Library - <cstring>
- C++ Library - <cuchar>
- C++ Library - <charconv>
- C++ Library - <cfenv>
- C++ Library - <cmath>
- C++ Library - <ccomplex>
- C++ Library - <expected>
- C++ Library - <format>
- C++ Library - <future>
- C++ Library - <flat_set>
- C++ Library - <flat_map>
- C++ Library - <filesystem>
- C++ Library - <generator>
- C++ Library - <initializer_list>
- C++ Library - <latch>
- C++ Library - <memory_resource>
- C++ Library - <mutex>
- C++ Library - <mdspan>
- C++ Library - <optional>
- C++ Library - <print>
- C++ Library - <ratio>
- C++ Library - <scoped_allocator>
- C++ Library - <semaphore>
- C++ Library - <source_location>
- C++ Library - <span>
- C++ Library - <spanstream>
- C++ Library - <stacktrace>
- C++ Library - <stop_token>
- C++ Library - <syncstream>
- C++ Library - <system_error>
- C++ Library - <string_view>
- C++ Library - <stdatomic>
- C++ Library - <variant>
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ cstring strxfrm() Function
The strxfrm() function is a built-in function in C++ which is defined in <cstring> header file. It is used for transforming string using locale-specific collation order.
This function is similar to the strcoll() function but the difference is that strcoll() function compares two strings based on the locale-specific collation order whereas, strxfrm() function transforms the string using locale-specific collation order.
Lets assume we have a project that shows the regional data. In this project, we need to transform the string based on the locale-specific collation order. In such cases, we can use the strxfrm() function.
Syntax
Following is the syntax of the strxfrm() function −
size_t strxfrm(char *dest, const char *src, size_t n);
Parameters
Parameters of the strxfrm() function are as follows −
- dest: This is the destination string where the transformed string will be stored.
- src: This is the source string which will be transformed.
- n: This is the maximum number of characters to be transformed.
Return Value
The strxfrm() function returns the number of characters that are transformed.
Example
We will take two strings str1 and str2 and then transform them using the strxfrm() function. This example help you to understand the usage of the strxfrm() function.
#include <iostream> #include <cstring> using namespace std; int main() { char str1[15]; char str2[15]; size_t ret; strcpy(str1, "abcd2z"); strcpy(str2, "ABCDEF"); ret = strxfrm(str1, str2, 5); cout << "Transformed string: " << str1 << endl; cout << "Number of characters need to transform the string completely: " << ret << endl; return 0; }
Output
Following is the output of the above C++ program −
Transformed string: ABCDEz Number of characters need to transform the string completely: 6