码迷,mamicode.com
首页 > 其他好文 > 详细

How to return NULL string

时间:2018-05-22 12:48:00      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:ios   spl   isp   none   ring   amp   view   one   null   

Q:

技术分享图片
std::string get_file_contents(const char *filename)
{
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}

}
View Code

waning:

lane_seg.cpp: In function ‘std::__cxx11::string get_file_contents(const char*)’:
lane_seg.cpp:303:1: warning: control reaches end of non-void function [-Wreturn-type]

A:

warning意思是:控制到达非void函数的结尾。就是说你的一些本应带有返回值的函数到达结尾后可能并没有返回任何值。这时候,最好检查一下是否每个控制流都会有返回值。

std::string get_file_contents(const char *filename)
{
    std::ifstream in(filename, std::ios::in | std::ios::binary);
    if (in)
    {
        std::string contents;
        in.seekg(0, std::ios::end);
        contents.resize(in.tellg());
        in.seekg(0, std::ios::beg);
        in.read(&contents[0], contents.size());
        in.close();
        return(contents);
    }
    return NULL;//or return " "; 
    
}

End

How to return NULL string

标签:ios   spl   isp   none   ring   amp   view   one   null   

原文地址:https://www.cnblogs.com/happyamyhope/p/9070693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!