2016-07-25 67 views
2

我是C++和Qt的初學者。目前,我正在研究一個我從開源網站獲得的Qt程序。這是一個個人支出的應用程序。當我試圖在Qt創建器中構建這個項目時,它出現錯誤:QT getline error與MinGW

C:\ Qt \ Saved project \ Expense-Tracker-master \ dataRead.h:152:error:'getline'was not declared in這個範圍 而{ ^

這裏下是相關的代碼((讀=函數getline(&線,& LEN,labelFile))!= -1):

std::vector<std::string> * readLabel(const char* labelToRead){ 
std::vector<std::string> * labels = new std::vector<std::string>; 
FILE * labelFile = fopen(labelToRead, "r"); 
if(labelFile == NULL) std::cout<<labelToRead<<std::endl; 
//TODO -- throw if failure 
char * line = NULL; 
size_t len = 0; 
ssize_t read; 
while((read = getline(&line, &len, labelFile)) != -1){ 
    std::string temp(line); 
    std::string label(temp.begin(), temp.end()-1); 
    labels->push_back(label); 
} 
free(line); 
fclose(labelFile); 
return labels;} 

我在谷歌搜索, getline()和MinGW編譯器之間似乎出了點問題。有人可以幫我解決這個問題。

另外,我已經包含了字符串頭。當我把「的std ::函數getline」,它顯示了另一個錯誤:

C:\Qt\Saved project\Expense-Tracker-master\dataRead.h:152: error: no matching function for call to 'getline(char**, size_t*, FILE*&)' 
    while((read = std::getline(&line, &len, labelFile)) != -1){ 
                ^
+0

焦點話題 - 你應該在C++(而不是C'FILE *')中使用'ifstream','ofstream'和'fstream'。 – Xiobiq

回答

0

我無法找到一個標準功能getline使用File *。我認爲你要找的功能是fgets。如果你使用Qt,我想你是用C++編寫的。 FILE *屬於C.您應該考慮使用C++函數而不是C(請參閱fstreams)。