文檔說:如何正確使用istream :: get(char * s,streamsize n,char delim);
istream::get (char* s, streamsize n, char delim);
// Extracts characters from the stream and stores them as a
// c-string into the array beginning at s
我試圖分析這個函數所做的事情。它需要一個「按價值」的指針。也就是說,它不能分配動態內存並將指針s
設置爲它。它只能改變指針s
指向的內容。
但是,如果函數不能執行動態內存分配,它如何返回長度未知的輸出?我應該如何使用這個功能?我應該預先分配內存並將指針傳遞給s
,然後自行刪除它嗎?
哪些文檔?此外,文檔實際上非常清晰 – 2013-02-18 15:01:58
好吧,我現在明白了,謝謝! http://www.cplusplus.com/reference/istream/istream/get/ – 2013-02-18 15:04:31
'cplusplus.com'不好,你應該用這個:http://en.cppreference.com/w/cpp/io/basic_istream/得到 – 2013-02-18 15:05:52