2016-08-14 99 views
-1

enter image description here 它導致一個Expected';'在頂級聲明之後,Xcode在這一行發生錯誤(在編譯期間):void intArray :: writeToFile(< #char * filename#>)使用Xcode編譯C++程序時發生錯誤

我聽說這是因爲Xcode在我的程序中加了「#」 ,那是爲什麼?我該如何刪除這兩個「#」?

非常感謝。

這裏是我的代碼:

#include <iostream> 
#include <fstream> 
#include <cstring> 
using namespace std; 

class intArray 
{ 
private: 
int *array; 
int length; 
public: 
intArray(char *filename); 
void sort(); 
~intArray(); 
void writeToFile(char *filename); 
}; 


intArray::intArray(char *filename) 
{ 
ifstream myFile(filename); 
int len=300; 
array=new int[len]; 
length=0; 
while(myFile>>array[length++]); 
length--; 
myFile.close(); 
} 

void intArray::sort() 
{ 
for(int i=0;i<length;i++) 
{for(int j=i;j<length;j++) 
    if(array[i]>array[j]) 
    {int temp; 
     temp=array[i]; 
     array[i]=array[j]; 
     array[j]=temp; 
} 
} 
} 

intArray::~intArray() 
{ 
delete [] array; 
} 

void intArray::writeToFile(<#char *filename#>) 
{ 
int step=0; 
ofstream outFile(filename); 
for(int i=0;i<length;i+=step) 
{outFile<<array[i]<<endl; 
    step++; 
} 
outFile.close(); 
} 

void main() 
{ 
intArray myArray("in.dat"); 
myArray.sort(); 
myArray.writeToFile("out.dat"); 
} 
+0

void intArray :: writeToFile(<#char * filename#>) { int step = 0; ofstream outFile(filename); (int i = 0; i

+0

什麼?你不是寫那行嗎? – molbdnilo

+0

...什麼?我在代碼的開頭寫了那行代碼。好吧,我已經同時發佈了一張關於我的代碼的圖片。 –

回答

0

我想我終於想通了這一個了,它似乎是XCode中如何處理其參數的建議,那些副作用,您可以與標籤(他們我想通常是藍色的)。

如果您在XCode中複製這樣的建議,它會被包圍並獲取奇怪字符「<#」和「#>」,並且在XCode中粘貼包含這些字符的文本會將該文本變爲藍色。

如果您開始編寫方法名稱,如writeToFile,XCode會建議從聲明中取得參數列表(顯示爲藍色)。
但是,直到你寫出它或接受了建議,文本纔會真正「存在」,並且直到該文本存在,否則不會造成混淆錯誤。

修復應該非常簡單:將光標置於藍色參數列表中,並按Enter接受它(或手寫文本)。

+0

謝謝你生動的答案,幸運的是,它終於奏效!許多thx〜 –