我正在讀取一個文件,並將數組(指針)的前端傳回到我的主函數中。我遇到的問題是它沒有複製單詞之間的空格。例如Hello Hello
作爲HelloHello
出現。從C++中用空格讀取文件
我開始使用getLine
來代替,並遇到了文件大小的問題。我將它設置爲500,因爲沒有文件將大於500,但大多數文件將低於500,我正在嘗試獲取文件的確切大小。
這裏是我的代碼:
char infile()
{
const int SIZE=500;
char input[SIZE];
char fromFile;
int i=0;
ifstream readFile;
readFile .open("text.txt");
while(readFile>>fromFile)
{
input[i]=fromFile;
i++;
}
cout<<endl;
returnArray=new char[i];//memory leak need to solve later
for(int j=0;j<i;j++)
{
returnArray[j]=input[j];
cout<<returnArray[j];
}
cout<<endl;
}
return returnArray[0];
}
它需要返回到焦炭的主要功能 – Aaron 2012-04-14 22:09:42
你的代碼有什麼可怕的壓痕... – Griwes 2012-04-14 22:22:13