為什么將NULL發送到std :: cout輸出后完全消失我花了好一會兒才弄清楚為什么某些cout輸出似乎消失在以太幣中了。罪魁禍首:std::cout<< "This line shows up just fine" << std::endl;const char* some_string = a_function_that_returns_null();if (some_string == 0)
std::cout<< "Let's check the value of some_string: " << some_string << std::endl;std::cout<< "This line and any cout output afterwards will not show up" << std::endl;上面代碼段的輸出將是:This line shows up just fineLet's check the value of some_string:因此,將NULL輸入cout將會禁用以后的所有輸出。為什么?以及如何解決?這并不是一直都發生的-具有相同代碼的同事會獲得所有預期的輸出。而且,如果您想知道為什么我不能僅通過if語句阻止將NULL饋入cout:我正在大型代碼庫中工作,并且不知道在哪里發生這種情況!我所知道的是我從來沒有出現過的cout陳述。更多信息:a_function_that_returns_null()實際上是getenv("HOST")。我通過在命令行上檢查echo $HOSTHOST變量是否為空。如果我這樣做export HOST=(bash風格),則輸出全部存在。getenv在修改HOST變量之前,我不知道HOST變量最初包含什么,也不知道最初返回什么。我所知道的(some_string == 0)是真的。
- 3 回答
- 0 關注
- 859 瀏覽
添加回答
舉報
0/150
提交
取消