是std :: string假设只有Ascii字符 [英] Is std::string suppose to have only Ascii characters

查看:104
本文介绍了是std :: string假设只有Ascii字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: string 应该在所有平台和标准编译器上保存一组Ascii编码的字符?

Is std::string supposed to hold a set of characters in Ascii encoding on all platforms and standard compilers?

换句话说,如果我这样做,我可以确定我的C ++程序将获得一组Ascii字符:

In other words, can I be sure that my C++ program will get a set of Ascii characters if I do this:

std::string input;
std::getline(std::cin, input);

编辑

更准确的话,我想确保如果用户输入a0我会得到一个 std :: string 有两个元素。第一个是 97 ,第二个是 48

In more accurate words, I want to make sure that if the user enter "a0" I will get a std::string with two elements. The first one is 97 and the second is 48

推荐答案

不,不能保证

std::string input;
std::getline(std::cin, input);

将只返回ASCII字符。 char 持有的值范围不限于ASCII字符。

will return only ASCII characters. The range of values that be held by a char is not limited to the ASCII characters.

如果您的平台使用

即使你的平台使用ASCII编码,如果 char 是一种未签名的类型,因此可以非常轻松地保留扩展ASCII字符

Even if your platform uses ASCII encoding, if char on the platform is an unsigned type, than it can very easily hold the extended ASCII characters too.

这篇关于是std :: string假设只有Ascii字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆