0
我想打印數字並在它們之間放置一個空格,但在編譯後我發現我留下了那個+運算符(C#練習)。當我運行這個程序時,它立即停止工作,但文本文件中有一個非常奇怪的輸出。爲什麼這樣的文本文件?奇怪的文件輸出C++
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i=0;
ofstream f("out.txt");
while(i != -1)
{
f << " " + i++;
}
return 0;
}
從551KB文件中的一些行:
deleted virtual method called
eleted virtual method called
leted virtual method called
eted virtual method called
ted virtual method called
ed virtual method called
d virtual method called
virtual method called
virtual method called
irtual method called
rtual method called
tual method called
ual method called
al method called
l method called
method called
method called
ethod called
thod called
hod called
od called
d called
called
called
alled
lled
led
ed
d
整數溢出會導致未定義的行爲,因此它可能永遠不會導致-1。例如,編譯器可以優化該測試。 –