string.size()有没有包括\0的大小
时间: 2024-06-05 11:12:08 浏览: 9
在 C++ 中,`std::string` 类型的 `size` 函数返回的是字符串中字符的数量,不包括字符串结尾的 null 字符 (`\0`)。如果你想要计算字符串中包括 null 字符在内的大小,可以使用 `std::string::length()` 函数。同时,在使用 C 风格字符串时,需要注意 `strlen` 函数只计算到字符串中第一个 null 字符为止,不包括 null 字符。
相关问题
string.size
string.size 是一个 C++ 中的字符串成员函数,用于返回字符串的大小,即字符串中的字符数。在 C++ 中,字符串是由字符数组表示的,以 null 字符 '\0' 结尾。可以通过调用 string 对象的 size() 函数来获取字符串的大小。
示例代码如下:
```cpp
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, world!";
std::cout << "Size of the string: " << str.size() << std::endl;
return 0;
}
```
输出结果:
```
Size of the string: 13
```
上述代码中,通过调用 `str.size()` 获取了字符串 `str` 的大小,即字符数。输出结果为 13,因为字符串 "Hello, world!" 包含了 13 个字符。
换成MediaStore.Video.VideoColumns.SIZE 依旧是0
这种情况可能是因为查询条件不正确导致的。你可以尝试使用以下代码来查询视频文件的大小:
```
Cursor cursor = resolver.query(uri, new String[]{MediaStore.Video.VideoColumns.SIZE}, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.SIZE));
// 处理文件大小
}
```
请注意,查询条件应该根据你实际的需求进行筛选,例如,可以通过 MediaStore.Video.VideoColumns.DATA 来限制查询结果只包括某个特定路径下的视频文件,或者通过其他字段来筛选满足特定条件的视频文件。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)