// Microsoft visual studio 2010
#include <iostream>
#include <string>
using namespace std;
int main()
{
char password;
string strPassword;
cin >> password; // only for single character
cin >> strPassword // for string storage
/* 1. but when I give input © it will store as single character c, not as ©.
I want to store it as © in my variable 'password' or 'strPassword' so that I can compare it with my pre-stored password
2. I also want to know about stdint.h
what is it ? why we need it and how it helps us (especially for streaming).
*/
return 0;
}

- 8,922
- 6
- 28
- 48

- 716
- 6
- 10
-
2See http://stackoverflow.com/questions/30197758/how-can-i-make-unicode-iostream-i-o-work-in-both-windows-and-unix-land for a general fix. I hesitate to close this question as a duplicate because my q+a covers much more. – Cheers and hth. - Alf Aug 08 '16 at 07:50
-
Read more about text encodings. C type `char` is not actually a character, it is just a single byte integer number. Usually it is used as a character of some character table or as a part of some string encoded with some rules. For example, if string encoding is UTF-8, the © representation requires 2 bytes. – ilotXXI Aug 08 '16 at 07:57
1 Answers
Regarding the first question about text encodings, you need the program to assume the same text encoding as it receives via input. One way to do that in Windows is to check what your ANSI codepage is, e.g. via commmand wmic os get codeset
. For example, a US or Norwegian will get 1252, the Windows ANSI Western codepage.
Then configure your console window to that, e.g. include
system( "chcp 1252" );
at the start of your program.
More generally you will need to use Unicode to deal with a larger character set. See my Q+A “How can I make Unicode iostream i/o work in both Windows and Unix-land?”. Hopefully it's not been invalidated by compiler evolution.
Regarding the second question about stdint.h
, that I suggest that you just google. It's surely a duplicate on SO. And SO is not a site for tutorials.

- 1
- 1

- 142,714
- 15
- 209
- 331