C++使用null部分填充数组

use*_*407 1 c++ arrays null

NoobQuestion:我听说填充char数组可以使用null char尽早终止.这是怎么做到的?我搜索了每一个谷歌的结果,但仍然空手而归.

Phi*_*ipp 5

你的意思是这样的:

    char test[11] = "helloworld";
std::cout << test << std::endl;
test[2] = 0;
std::cout << test;
Run Code Online (Sandbox Code Playgroud)

这输出

helloworld
he
Run Code Online (Sandbox Code Playgroud)