Transcript for:
Understanding C++ Wide Character Types

so in the series of learning c plus plus programming language in the previous video we have discussed carrier type in c plus plus so now in this video we will see w care underscores t this stereotype this is for white characters in c plus this is almost same as ah cad type which is used to you know store those alphabet digits you can say the letters or special symbols punctuation marks and these things this also used to store these things but few differences are there right now what are those differences how this is different from cairo type and why we need this hair type if you have cadet then why we need this wide character data type right all these things will discuss in this video with the help of a program i will show you practical also right now before that just want to tell you one thing geeksfornix has come up with a hiring challenge called jobathan which will be on 21st of june and the time is 8 pm to 10 30 pm and this contest is for the candidates who are looking for freshers or you know intern job opportunities these six companies will be participating in this contest to fulfill their hiring requirements so first you have to register for this contest after registering for the contest you have to go through the job descriptions even right and then you have to register for one or more companies that you are interested in your profile will be selected will be considered for the company if you have registered for that thing now what is the format how many questions you will get total 18 question you will get and the total mass would be 175 marks three coding questions would be there right three dsa coding problems of 100 marks and the language for these to solve these recording problems are what c plus plus java and python now five mcqs for programming logic five mcqs for quantitative activity aptitude and five mcqs for logical reasoning these mcqs would be of 25 marks each so total 175 marks would be there and there is five percent penalty for each wrong submission so better to first use that compiling test against the sample test cases before you actually submit your answer right and only individual participation is allowed an interview shortlisting would be done for you know specific companies based on their own criteria so to find out more rules and regulations you go to their contest page the link would be in the description box of this video you go and check out from there so and this event is what it's a recurring event it happens on 21st of every month right so you just mark your calendars and you keep track so now all the relevant links and details i'll put in the description box of this video you can go and check out now let's see what is cap or you can say white character data type in c plus plus see same it is used to store the characters wide characters it is known as first of all white character white characters right so the difference is what can take one bite right it take two bites or four bites sometimes it depends on the compiler you are using in my compiler in my machine it is taking two bytes i will show you how to calculate size of this data type right you can check out on your own machine maybe it will take four bytes right so now see can take only one byte means eight bits so using cad air type we can represent only how many characters or you can say the things how many characters or symbols only 256 right zero to 255 like capital a b c d small a b c d some 0 to 9 numbers and some symbols right but c and that it is used to represent what this we follow what the m the famous character encoding scheme is what sky we follow this thing right but now in the world there are many languages it's not like that only these abcd and these symbols we have so there are many languages in the world right many characters are there many symbols are there emoji you are using nowadays emoji is what also coded right in just a sequence of some unicode characters one or more unicode characters or numbers right so for storing those things right we cannot use this cad type because using this we can store only 256 values right that is why we use wide character data type same how to what is the syntax you have to write w care underscore t the name of the variable suppose i am taking ch but prefix which is used is l first of all l then in single quote you just write down a character for simplicity purpose i am just taking smalling right although small a we can represent this thing using care also but i am just taking one simple simple example right when will uh you know write a program then i'll store a wide character or a character you can say from different language right now see this l is telling the compiler that it is wired character and it is going to take two bytes or maybe four bytes it depends on the compiler in my machine it is taking two bytes so this a now would be stored in two bytes memory right so mainly w this type is used when we deal with international languages like russian japanese these languages they have different different characters and many things many symbols to store those are we are not able to you know represent those symbols using care data type so now that is why if suppose it take two bytes so how many the range of this stereotype would be 0 2 you can say or you can say 6 5 5 i think 3 6. these many characters or symbols or anything you can say we can represent using wide carrier type we can store using white cad air type and with help of care we can represent only 256 values characters right so have you use sky table one more character encoding is what unicode unicode standard or you can see unicode table is there as you can see this is the unicode table in this table we have a unique number for each character or symbols or punctuation marks or emoji even for emojis we have unique characters right and it is still evolving the recent unicode you know you can say version is what 14.0 and unicode 15.0 will be coming in september they are planning to release this version on uh 15 13 september 2022 right and for this now what is this unicode it provide unique number unique code for each character right see many character encodings are there just you can google out and there will be list of character encodings right the famous one is sky we generally use and they are limited right they are not suitable to represent all the languages from all over the from all over the world right so a new character coding would be introduced and some other limitations in you know previous character encodings role so they are conflicting with each other sometimes same number is used to represent two different different characters right or maybe the same character is having different different numbers and different different encoding schemes so generally any computer like especially the server have to support multiple encoding schemes and sometimes when we transfer data using these encoding schemes between different character encoding schemes like one computer is following this encoding scheme another computer is holding another encoding scheme you know character encoding so there would be a risk like the loss of data or you can say the data correction you are sending some other data receiving some other data because of the different different platforms or different different character recording scheme but unicode provide a single character unique number right to every character irrespective of the platform the language irrespective of anything unique number it is going to provide right so the recent version they're going to release is 15.0 in which they have i think in unicode 14.0 version there are uh i am not sure but these many characters are there some emojis many symbols are there and they have encoded like uh almost 159 scripts script means uh for example demna is a script or you can say lipi for hindi language dev nagar is a leapy so like this many scripts are there for different different languages so they have encoded 159 scripts in this so in 15.0 they have added these many new characters uh two new scripts they have added and 20 new emojis they have added right this number you have to check out like in 14.0 i think these many characters are there but you have to confirm you just confirm you just google it out right so this white character can take these many values which correspond to the unicode table from unicode table right as you can see this is the unicode table here we have unicode number and you can say the decimal also corresponding to that you can say the letter or the digit or the symbol like suppose for a we have decimal we have 65 and unicode encoding we have u plus 0 0 41. right like this we have unicode you can say the number for each character in this table so i think the basic about this this data type is clear to you guys let me show you a practical let me show you a program right see we use this when we deal with international languages so frankly speaking you you you have to use only care data right because you are not dealing with international languages when you are writing a program and all right but for this you know if this is a built-in area type in c plus plus so you have some idea about the stereotype i guess you've got the basic idea about this data type but there is many thing about this data type right in detail maybe we can discuss in a separate video this is just to give you an overview about wcad type and what is unicode and all these things right so see this is a file a program w care underscore t dot cpp there is nothing much in this we have just that header file name space std and we have declared a variable defined a variable ch the data type of this is w care underscore t and l in single quote i am writing this symbol but first of all let me just write down only simple character a we are using right now second thing we are will just print c out ch the character but for dealing with this w care wide characters because this now a is now would be considered as wide character so for printing this you see out is what for character output but we use wc out wide character output right because a is now a wide character and then we are just finding out the size of this w care underscore t data type that's it right now let me just save it and run it will simply print character is a and the size is two byte this is the difference a is the character but the size is it is taking in my machine two bytes in some machine maybe it can take four bytes it depends on the compiler you are using right but now see let's take another thing let's see see this is unicode table i'm referring this is the unicode table here we have decimal values we have so suppose this symbol i am taking this g and i don't know what is the symbol let me just take this symbol control c and control just paste it because obviously from our keyboard we cannot write down we cannot print these kind of symbols we are limit you know we have limited resources the keyboard is you can say limited having limited numbers and alphabets and all so just copying pasting here and let's just save it and run now see what output you will get only it is printing to the size it is not printing this this symbol why so because this output this console is not compatible to print these kind of things international symbols and these languages limited things it can print but it has the num this the symbol has been stored for sure in the memory in two bytes of the memory right now if you want to print the decimal value of this symbol then just type cast this and write down int right now let me just run this and see it is printing 284 284 is the decimal you know number for this symbol like for a the decimal is 65 for this decimal is 284 as you can see in the table this they see 280 and from above we have fourth column so 284 right or if you want to check the character in coding and you can then unicode encoding of the character then we have a character map you just search in the search bar character map this is inbuilt app and you can see you can select anything see and here you will see the unicode encoding u plus 0 0 d6 right so for a for capital a let's see the unicode encoding is u plus zero zero four one and the decimal is what sixty five so this is how you can use this wide character type it's not for character it can be used to uh store the string you know white character string also right and as for simple string we have some predefined functions to find out string lines like strle and you can to concatenate two strings so for wide character strings also white strings also we have predefined functions those also we will discuss in later videos like what are those predefined functions the header file you have to include and how to use those functions and on this video just to give you an overview about this wide character type i hope this is clear to you guys now now you can you can from unicode table you just copy paste a symbol you can just store that symbol and see what it is printing the decimal value of that symbol and all right so in the next video we will see the remaining built-in data type in c plus so now i'll see in the next video till then bye take care