ascii 和 unicode 在处理级别上有什么区别吗?
There is any difference between ascii and unicode at processing level?
假设我有一个像
这样的函数
template<typename charT>
void fun(std::basic_ostream<charT>& out, std::basic_fstream<charT>& file)
{
std::basic_string<charT> str;
file>>str;
out<<str;
}
注意:文件编码为 utf-8
我不了解 Unicode。我可以将此函数用于 ASCII 和 Unicode,还是使用 basic_type 构建一个 class 以便 class class 可以用于 Unicode 和 ASCII。
我的问题是 ASCII 和 Unicode 在处理级别上有什么区别吗?
编辑:
处理级别意味着对字符串进行操作,例如追加、打印和从文件中获取字符串。
为什么我要问这个问题是 std::string 和 std::wstring 是 basic_string 的 typedef ed 版本,具有 char 和 wchar_t
和 std::cout 和 std::wcout 是 std::basic_ostream 的 typedef ed 版本,具有 char 和 wchar_t 但两个代码相同。
在这两种情况下,区别仅在于内存。
所以我使用 basic_type 构建了一个 class 以便 class 可以同时用于 ASCII 和 Unicode。
There is any difference between ascii and unicode
是的。它们是不同的编码并且不相同。因此,存在差异。
Can I use this function for both ASCII and Unicode
是的。对于 UTF-8(假设字节大小为 8 位)。
该函数不执行任何需要对这些编码进行不同处理的操作。
尽管如此,如果您想从终端读取输出,这取决于终端的功能和配置,它使用哪种编码来显示输出。如果它与您正在打印的内容不匹配,则输出可能会被误解。
假设我有一个像
这样的函数template<typename charT>
void fun(std::basic_ostream<charT>& out, std::basic_fstream<charT>& file)
{
std::basic_string<charT> str;
file>>str;
out<<str;
}
注意:文件编码为 utf-8
我不了解 Unicode。我可以将此函数用于 ASCII 和 Unicode,还是使用 basic_type 构建一个 class 以便 class class 可以用于 Unicode 和 ASCII。
我的问题是 ASCII 和 Unicode 在处理级别上有什么区别吗?
编辑:
处理级别意味着对字符串进行操作,例如追加、打印和从文件中获取字符串。
为什么我要问这个问题是 std::string 和 std::wstring 是 basic_string 的 typedef ed 版本,具有 char 和 wchar_t
和 std::cout 和 std::wcout 是 std::basic_ostream 的 typedef ed 版本,具有 char 和 wchar_t 但两个代码相同。
在这两种情况下,区别仅在于内存。
所以我使用 basic_type 构建了一个 class 以便 class 可以同时用于 ASCII 和 Unicode。
There is any difference between ascii and unicode
是的。它们是不同的编码并且不相同。因此,存在差异。
Can I use this function for both ASCII and Unicode
是的。对于 UTF-8(假设字节大小为 8 位)。
该函数不执行任何需要对这些编码进行不同处理的操作。
尽管如此,如果您想从终端读取输出,这取决于终端的功能和配置,它使用哪种编码来显示输出。如果它与您正在打印的内容不匹配,则输出可能会被误解。