天天看點

How to return NULL string

Q:

How to return NULL string
How to return NULL string
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]      
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 " "; 
    
}