簡體   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