c++ - What is the difference between locale and Encoding ( Terminal ) -


i have tried few ways set terminal 'encoding' c++ program. change locale. or lang variable.

still able enter characters of different encoding lang ( , output of nl_langinfo(codeset) )

but , if go terminal > set character encoding > iso-8859-15 ( or ) allowing iso-8859-15 . can achive same thing ( setting gui ) c++ program ?

i used setlocale(lc_ctype,"") set encoding terminal encoding , uses lang variable.and allows other characters too.

( after terminal > set character encoding > iso-8859-1 ( latin1 ) )

>setenv lang en_us.iso885915 --> latin9 >./a.out  current locale : c lang info : ansi_x3.4-1968 trying change locale c "" current locale : en_us.iso885915  lang info : iso-8859-15 enter string :¤¦¨´¸¼½¾ dfsafas  --> these latin1 charaters !! entered string : ¤¦¨´¸¼½¾ dfsafas --> printed !! 

so , brought me down question if understanding locale , encoding correct or not.

can please clarify difference?

encoding part of locale settings , terminals affects how terminal displays , process input.

terminal encoding , locale setting program running withing terminal pretty independent , might not match or can misconfigured.

setlocale() set or query program's current locale.

terminals spawns new shell , setting lang or lc_* environment variables affect programs run withing shell.

also setting locale or encoding not prevent "other" characters entered.

this answer should clarify things.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -