下面是我的代碼:C++爲什麼我的str [i]輸出是空的?
char str [80];
int n;
n = MAX + (rand() % 1000 + 1);
cout << "number: " << n << endl;
constructArray(str, n);
void constructArray (char str [], int n)
{
for (int i = 0; i < n; i++)
{
while (n > 0)
{
// get last pair of digits
str [i] = n%10;
n/= 10;
}
cout << str[i] << endl;
}
}
我想不通,爲什麼我的編譯器犯規輸出的任何值。 它工作,如果我沒有實現數組。
任何幫助將不勝感激。
解決此類問題的正確工具是您的調試器。在*堆棧溢出問題之前,您應該逐行執行您的代碼。如需更多幫助,請閱讀[如何調試小程序(由Eric Lippert撰寫)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。至少,您應該\編輯您的問題,以包含一個[最小,完整和可驗證](http://stackoverflow.com/help/mcve)示例,該示例再現了您的問題,以及您在調試器。 –
你是否正在運行[這個問題](終於,http://stackoverflow.com/questions/19562103/uint8-t-cant-be-printed-with-cout/19562163#19562163)? –
這個問題沒有顯示任何研究工作;它不清楚或沒有用 –