java - 字符串中的空终止

标签 java c++ c string

是的,我确实检查了其他线程并得出了结论。 我只是想让你确认一下,以免我有任何误解。

Java String objects are not null terminated.

C++ std::string objects are also not null terminated

C strings or C-style strings if you will (array of characters), are the only strings that are null-terminated.

正确还是不正确?

最佳答案

C 字符串是以 0 结尾的字符串。不过,您不会被迫在 C 语言中使用它们。

C++ std::string 和 Java 字符串都是计数字符串,这意味着它们存储它们的长度。

But C++ std::strings are also followed by a 0 since C++11 ,如果(通常情况下)它们不包含任何嵌入的 0,则使它们以 0 结尾,以便与以 0 结尾的字符串 API 实现更好的互操作性。

关于java - 字符串中的空终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28707524/

相关文章:

c++ - 从 C++ 核心转储中推断源代码行号

c++ - #including <iostream> 中断共享对象的链接

c - 相加直到遇到负数

java - 语音识别 Android NPE

java - Spring 安全 : Multiple HTTP Config not working

java - 安卓 : Serializing an array of Objects

java - 基本搜索引擎 - 爬行之后下一步是什么?

c++ - 在 Qt Symbian C++ 中删除 QPushButton 的文本

c - 使用 golang 的 Windows Hook

选择很多情况而不是 c >= '0' && c <= '9' 到 0-9 数字检查