`end1' is not a member of `std'

好不容易借到了C++ Primer 4/e中文版,结果第一个范例就出现了一堆错误:

add.cc: In function `int main()’:
add.cc:13: error: `end1′ is not a member of `std’
add.cc:15: error: `V1′ was not declared in this scope
add.cc:15: error: `V2′ was not declared in this scope
add.cc:17: error: `end1′ is not a member of `std’

原来endl是”l”不是”1″,v1,v2大小写有分,从书本里面自己动手diy就会有这些盲点没注意到。

课本对endl有更详细的解释:
‘endl是个特殊值,称为操控器(manipulator),当这个值被写至output stream时,会输出一个换行符号并将输出装置的缓冲区(buffer)清空。藉由清空缓冲区我们便能确定用户立即看到写至stream的文字。’

另外要当心的是,‘程式员经常在除错(debugging)时插入一些列印述句。这种述句一定要记得清空stream,否则输出文字有可能再程式当掉时残留于缓冲区,导致对程式当调位置的错误推断。’