-1


我正在尝试在我的自定义 OpenWRT 发行版中编译一个简单的 C++ 代码,但我的getline指令出错。
这是我的代码的快照:

#include <stdio.h>                                                                                                                                                                                                                    
#include <string.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <sys/stat.h>
...

ifstream infile(MODEL);
if (infile.fail())
    return;
getline(infile, model);

...

我收到这种警告(我正在使用 -Werror 标志进行编译)

In file included from /home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/iostream:30:0,
                 from fmsnmpwalk.cpp:5:
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream: In instantiation of 'std::basic_istream<charT, traits>& std::getline(std::basic_istream<charT, traits>&, std::basic_string<Ch, Tr, A>&, charT) [with charT = char; traits = std::char_traits<char>; Allocator = std::allocator<char>]':
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream:114:16:   required from 'std::basic_istream<charT, traits>& std::getline(std::basic_istream<charT, traits>&, std::basic_string<Ch, Tr, A>&) [with charT = char; traits = std::char_traits<char>; Allocator = std::allocator<char>]'
fmsnmpwalk.cpp:47:23:   required from here
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream:97:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
  for(i=0;i<n;++i){
           ^
cc1plus: all warnings being treated as errors

我不明白是什么问题。
在我的 OpenWRT 发行版上,我使用的是gcc 5.xuClibc-0.9.33.2
任何帮助表示赞赏。谢谢!

4

1 回答 1

1

正如错误所说:

错误:有符号和无符号整数表达式之间的比较 [-Werror=sign-compare]

因此,您for(i=0;i<n;++i){在 uClibc++ 中的某处(即 in std::getline)中有此代码,其中in具有不同的符号(也许,i是一个intwhilen代表一些长度并且是一个size_t,它是无符号的)。

你可以用类似的东西关闭这个警告-Wno-sign-compare

于 2016-06-16T16:43:11.360 回答