简体   繁体   English

MinGW的Qt getline错误

[英]Qt getline error with MinGW

I am a beginner in both C++ and Qt. 我是C ++和Qt的初学者。 Currently, I am studying a Qt program which I got it from open source website. 目前,我正在研究Qt程序,该程序是从开源网站获得的。 It's a personal expense track Apps. 这是个人支出跟踪应用程序。 When I am trying to build this project in Qt creator, it appears the error: 当我尝试在Qt Creator中构建此项目时,出现错误:

C:\\Qt\\Saved project\\Expense-Tracker-master\\dataRead.h:152: error: 'getline' was not declared in this scope while((read = getline(&line, &len, labelFile)) != -1){ ^ C:\\ Qt \\ Saved project \\ Expense-Tracker-master \\ dataRead.h:152:错误:在此范围内未声明'getline'while((read = getline(&line,&len,labelFile))!= -1) {^

Here under are the related code: 以下是相关代码:

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;}

I search in Google, it seems that something goes wrong between getline() and MinGW compiler. 我在Google中搜索,在getline()和MinGW编译器之间似乎出了点问题。 Could someone help me out on this. 有人可以帮我这个忙。

Plus, I include the string header already. 另外,我已经包含了字符串标题。 When I put 'std::getline', it shows another error: 当我输入“ 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){
                                                      ^

I can't find a standard function getline working with FILE*. 我找不到使用FILE *的标准函数getline I think the function you're looking for is fgets . 我认为您要寻找的功能是fgets If you're using Qt, I guess you're coding in C++. 如果您使用的是Qt,我想您正在使用C ++进行编码。 FILE* belongs to C. You should consider using C++ functions instead of C (see fstreams ). FILE *属于C。您应该考虑使用C ++函数而不是C(请参阅fstreams )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM