krohn211
2010-02-18 17:54:43 UTC
int main()
{
char *test = new char[10];
test[0] = 'a';
test[1] = 'b';
test[2] = 'n';
test[3] = 't';
test[4] = 'g';
test[5] = '\0';
cout << test;
while(1){
}
}
The above program prints out nothing because it is stuck in the infinite loop and doesn't do the cout. However, if I add an endl after test, it prints out. The odd thing is with this program:
int main()
{
char *test = new char[10];
test[0] = 'a';
test[1] = 'b';
test[2] = '\n'; //changed from n to \n
test[3] = 't';
test[4] = 'g';
test[5] = '\0';
cout << test;
while(1){
}
}
This program prints out ab and then stops. I thought \n didn't flush the buffer. Why is \n acting like endl? Shouldn't the last program print out nothing like the first program?