繁体   English   中英

使用 '\\0' 停止 While 循环

[英]Stopping a While Loop with '\0'

当字符数组到达 '\\0' 时,我无法停止 while 循环。 我知道这总是任何 char 数组的最后一个元素,所以我不明白为什么下面的代码永远不会结束循环。 任何帮助将不胜感激。

char randomString[] = "testSTRING";

int counter = 0;
while (randomString[counter] != '\0')
    cout << "test";

尝试这个:

char randomString[] = "testSTRING";

int counter = 0;

while (randomString[counter++] != '\0')`

    cout << "test";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM