如何获取特殊字符输入并存储在字符或字符串变量中?特殊字符表示©或 ž
how to get spcecial charecter input and store in char or string variable? special characters means © or ž
// 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;
}
关于文本编码的第一个问题,您需要程序假定与通过输入接收到的文本编码相同。在Windows中这样做的一种方法是检查您的ANSI代码页是什么,例如通过命令wmic os get codeset
。例如,美国人或挪威人将获得1252,Windows ANSI Western代码页。
然后配置你的控制台窗口,例如包括
system( "chcp 1252" );
在你的程序开始。
一般来说,您需要使用Unicode来处理更大的字符集。请参阅我的Q+A “我如何使Unicode iostream I/o在Windows和Unix-land中都工作?”希望它没有因为编译器的进化而失效。
关于stdint.h
的第二个问题,我建议你谷歌一下。这肯定是SO上的复制品。SO不是一个教程网站
相关文章:
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 当字符串存储在变量中时,如何将字符串转换为wchar_t
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 从字符串变量中逐字符读取单词
- 对函数 PlaySound 使用字符串变量
- C++中的字符串变量
- 如何在 c++ 中将字符串迭代器变量传递给函数?
- 如何使用C++将字符串中的字符转换为整数变量
- 字符串变量,比如说"字符串str",可以直接复制到数组中吗?
- 我可以用字符串变量而不是它的名字创建容器吗? C++
- 字符串变量的大小
- 使变量字符串忽略转义序列
- 如何在 C 宏中将变量字符串与文字字符串连接起来?
- 在 Py_BuildValue 中返回变量字符串
- 如何将字符串作为变量与另一个变量字符串进行比较
- 从变量字符串中提升文件系统路径
- 用变量字符串声明设置容器
- 通过变量(字符串)调用obejct和方法
- C++创建文本和变量字符串
- 如何在循环中使用变量字符串