전체 file.txt를 char 배열로 읽으려고합니다. 그러나 몇 가지 문제, 제안하십시오 =]텍스트 파일을 char 배열로 읽어들입니다. C++ ifstream
ifstream infile;
infile.open("file.txt");
char getdata[10000]
while (!infile.eof()){
infile.getline(getdata,sizeof(infile));
// if i cout here it looks fine
//cout << getdata << endl;
}
//but this outputs the last half of the file + trash
for (int i=0; i<10000; i++){
cout << getdata[i]
}
아니면 누군가가 문자 배열에 텍스트 파일을 저장하는 더 좋은 방법을 제안 할 수 있습니다. – nubme
장난감 앱 이외에는 이렇게하면 무제한 메모리 할당을 막을 수 있습니다. – seand
세미콜론이 누락 된 것 같습니다. –