🔒 Locked
Using native language .
Advertisement
Original Post
If i want to use functions like cout or iostream ones to read from a file characters that are NOT english , how can i do it ? I mean , when i try to do it - i get some strange characters instead of the ones i am supposed to get . How can i solve this ?
[edited by - Joe Forhens on February 17, 2003 3:49:25 PM]
and what if i want to read some strings from a file and then manipulate or cout them ?
Exactly . What can i do ?
This subject can get arbitrarily complex, depending on what you are doing and how you approach it, so I''ll only give a few pointers :
a) Make sure you know which character encoding / code page the file uses (there are incompatibilities between DOS/console code pages and windows code pages)
b) Use the wide version of streams and strings : std::wcout, std::wfstream, std::wstring, wchar_t (instead of char)
c) Read up on locales and internationalisation (often written as "i18n")
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
a) Make sure you know which character encoding / code page the file uses (there are incompatibilities between DOS/console code pages and windows code pages)
b) Use the wide version of streams and strings : std::wcout, std::wfstream, std::wstring, wchar_t (instead of char)
c) Read up on locales and internationalisation (often written as "i18n")
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
It can''t be complex ! I just wanna read a file wich contains an alphabet that is not english ! . And not whatever language , the language that is my second one in windows .
Language is mostly irrelevant. Encoding is what's important. Some common encodings for character sets:
ASCII: Single byte characters with values from 0 to 127. 128 and greater are non-standard and can be anything. So, if the character you want isn't between 0 and 127, it may not be usable except in one application in one environment.
UTF-8: Variable byte (1 to 6) characters that can represent values from 0 to 232-1. Backwards compatible with ASCII (all valid ASCII is valid UTF-8). This is becoming the most common character set in *nix-land. In C/C++ a normal 'char' can be used for UTF-8, but some characters will take up multiple characters. String sizes are therefore measured in 'bytes' and not 'characters'.
UCS-2: Two byte characters that can represent values from 0 to 232-1. In C/C++ a 'wchar_t' is used to store UCS-2 (well, sometimes, you might want to use 'short' or whatever type is 2-bytes instead; a wchar_t could be too large if it was meant for UCS-4, like it is in some cases).

[edited by - Null and Void on February 18, 2003 5:20:32 PM]
ASCII: Single byte characters with values from 0 to 127. 128 and greater are non-standard and can be anything. So, if the character you want isn't between 0 and 127, it may not be usable except in one application in one environment.
UTF-8: Variable byte (1 to 6) characters that can represent values from 0 to 232-1. Backwards compatible with ASCII (all valid ASCII is valid UTF-8). This is becoming the most common character set in *nix-land. In C/C++ a normal 'char' can be used for UTF-8, but some characters will take up multiple characters. String sizes are therefore measured in 'bytes' and not 'characters'.
UCS-2: Two byte characters that can represent values from 0 to 232-1. In C/C++ a 'wchar_t' is used to store UCS-2 (well, sometimes, you might want to use 'short' or whatever type is 2-bytes instead; a wchar_t could be too large if it was meant for UCS-4, like it is in some cases).

[edited by - Null and Void on February 18, 2003 5:20:32 PM]
i don''t get exactly what you mean , could u please present some code on how you would read your name from a file and cout it using a language other than english ? I don''t mean anything fancy . Just read a string wich is written in a language other than english and cout it ... And i don''t mean a general purpose program that would load any alphabet , simply ur native''s languages(if it''s not english) ...
Your question keeps getting answered, and you keep ignoring the answer. Put simply, if it''s not in the ASCII character set, you need to start worrying about codepages and unicode and wide characters and suchlike. There''s no two ways about it, and you won''t save much time by making it specific to one language. I suggest you start reading up on the resources you''ve been directed to.
Don''t listen to me. I''ve had too much coffee.
Don''t listen to me. I''ve had too much coffee.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement