0
爲什麼這裏的返回字符串上有各種垃圾?C++返回字符串不斷變垃圾
string getChunk(ifstream &in){
char buffer[5];
for(int x = 0; x < 5; x++){
buffer[x] = in.get();
cout << x << " " << buffer[x] << endl;
}
cout << buffer << endl;
return buffer;
}
ifstream openFile;
openFile.open ("Bacon.txt");
chunk = getChunk(openFile);
cout << chunk;
我得到它有它的結束垃圾,即使我調試說,我的緩衝區充滿正確的字符字符串中垃圾的負荷。
謝謝,C++比Java困難得多。
謝謝,我會試一試。 – 2013-04-08 23:41:02