2015-09-06 62 views
-2

我正在爲我所有的函數調用此錯誤消息,我就被初始化爲下文頭文件gcc編譯錯誤4.2.2。但工作在Xcode 6.4

void Initialisation(std::fstream &file, std::string name); 
void Input(std::fstream &file, std::string name); 
void Print(std::fstream &file, std::string name); 
void Update(std::fstream &file, std::string name); 
void Insert(std::fstream &file, std::string name); 
void Delete(std::fstream &file, std::string name); 

,並呼籲在主文件中像這樣

Initialisation(dataFile, "hardware.dat"); 

hardware.cpp: In function 'void Initialisation(std::fstream&, std::string)': hardware.cpp:13: error: no matching function for call to 'std::basic_fstream<char, std::char_traits<char> >::open(std::string&, std::_Ios_Openmode)' /packages/gcc/4.2.2/lib/gcc/sparc-sun-solaris2.10/4.2.2/../../../../include/c++/4.2.2/fstream:778: note: candidates are: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]

+1

GCC 4.4.2不能正確執行C++ 11。 –

+0

@πάνταῥεῖ我如何解決它? –

+0

如果你告訴任何人錯誤信息是什麼,它*可能會有所幫助。 – molbdnilo

回答

0

使用std::string作爲文件操作的參數在C++ 11中引入,僅在gcc 4.7左右完全支持(這個特性很可能在舊版本中可用) (因爲「compler/runtime提供的新功能通常是一次引入的」),但4.2.2是在2007年發佈的4.2.0中的錯誤修復,所以它大約有8年的歷史目前爲止。

編輯:據我所知,XCode 6.4使用了一個版本的Clang 3.6,它應該有完整的C++ 11支持。結束編輯。編輯2:您可以使用-std=c++03作爲XCode編譯器的額外選項,這可以確保編譯在XCode中的代碼也可以在gcc 4.2.2編譯器中編譯。結束編輯2

當然,如果您不需要任何其他C++ 11功能,則可以用x.open(name.c_str())替換x.open(name)

我會然而有專人負責爲您選擇學校的編譯器和查詢它是否是使用編譯器是迄今爲止過時的故意決策的聊天......

+0

如何在XCode編譯器上使用-std = C++ 03? –

+0

我沒有使用過XCode IDE,所以我不確定細節,但是在某個地方你應該是一個「編譯器選項」設置集合,它可以有一個「標準跟隨」選項,或者應該有一個指定「附加選項」的方式。 –