MinGW的Qt getline错误
Qt getline error with MinGW
我是 C++ 和 Qt 的初学者。目前,我正在研究从开源网站获得的 Qt 程序。这是一个个人开支跟踪应用程序。当我尝试在 Qt Creator 中构建此项目时,出现错误:
C:\Qt\Saved project\Expense-Tracker-master\dataRead.h:152: 错误: 'getline' 未在此范围内声明
while((read = getline(&line, &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;}
我在Google中搜索,好像getline()和MinGW编译器之间出了问题。有人可以帮我解决这个问题吗?
另外,我已经包含了字符串 header。当我输入 '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){
^
我是 C++ 和 Qt 的初学者。目前,我正在研究从开源网站获得的 Qt 程序。这是一个个人开支跟踪应用程序。当我尝试在 Qt Creator 中构建此项目时,出现错误:
C:\Qt\Saved project\Expense-Tracker-master\dataRead.h:152: 错误: 'getline' 未在此范围内声明 while((read = getline(&line, &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;}
我在Google中搜索,好像getline()和MinGW编译器之间出了问题。有人可以帮我解决这个问题吗?
另外,我已经包含了字符串 header。当我输入 '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){
^