A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_locale_length.htm below:

C++ Locale Library - length

C++ Locale Library - length Description

It returns the number of external characters in the range [from,from_end) that could be translated into at maximum of max internal characters, output as if applying codecvt::in.

Declaration

Following is the declaration for std::ctype::length.

C++98
	
int length (state_type& state, const extern_type* from,
            const extern_type* from_end, size_t max) const;
C++11
int length (state_type& state, const extern_type* from,
            const extern_type* from_end, size_t max) const;
Parameters Return Value

It returns the length of the sequence of characters, in terms of translated internal characters.

Exceptions

No-throw guarantee − never throws exceptions even if an exception is thrown, there are no changes in the facet object.

Data races

The facet object is accessed.

Example

In below example explains about std::ctype::length.

#include <iostream>
#include <locale>
#include <cwchar>
#include <cstddef>

int main () {
   typedef std::codecvt<wchar_t,char,std::mbstate_t> facet_type;

   std::locale loc;
   const facet_type& myfacet = std::use_facet<facet_type>(loc);

   const char source[] = "sairamkrishna mammahe";
  
   std::mbstate_t mystate;
   const char * pc;
   wchar_t * pwc;

   std::size_t length = myfacet.length (mystate, source, source+sizeof(source), 30);

   wchar_t* dest = new wchar_t[length];
   myfacet.in (mystate, source, source+sizeof(source), pc, dest, dest+length, pwc);

   std::wcout << dest << std::endl;

   delete[] dest;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

sairamkrishna mammahe

locale.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4