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(, std::ios::end);
contents.resize(in.tellg());
in.seekg(, std::ios::beg);
in.read(&contents[], contents.size());
in.close();
return(contents);
} }

waning:

lane_seg.cpp: In function ‘std::__cxx11::string get_file_contents(const char*)’:
lane_seg.cpp::: 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(, std::ios::end);
contents.resize(in.tellg());
in.seekg(, std::ios::beg);
in.read(&contents[], contents.size());
in.close();
return(contents);
}
return NULL;//or return " "; }

End

How to return NULL string的更多相关文章

  1. 你写的return null正确吗?

    上次一篇“你写的try…catch真的有必要吗”引起了很多朋友的讨论.本次我在code review又发现了一个问题,那就是有人有意无意的写出了return null这样的代码,例如: public ...

  2. org.apache.ibatis.binding.BindingException: Mapper method 'attempted to return null from a method with a primitive return type (long).

    一.问题描述 今天发现测试环境报出来一个数据库相关的错误 org.apache.ibatis.binding.BindingException: Mapper method 'attempted to ...

  3. java中,return和return null有什么区别吗?

    java中,return和return null有什么区别吗? 最大的区别:return;方法的返回值必须是void!return null;方法的返回值必须不是 原始数据类型(封装类除过)和void ...

  4. 在Java中,return null 是否安全, 为什么?

    Java代码中return value 为null 是不是在任何情况下都可以,为什么不会throw NullPointerException? Java语言层面:null值自身是不会引起任何问题的.它 ...

  5. attempted to return null from a method with a primitive return type (int).

    java接口文件 package com.cyb.ms.mapper; import org.apache.ibatis.annotations.Param; public interface Acc ...

  6. Mapper method 'com.xxxx.other.dao.MyDao.getNo attempted to return null from a method with a primitive return type (int)

    使用myBatis调用存储过程的返回值,提示错误信息: org.apache.ibatis.binding.BindingException: Mapper method 'com.xxxx.othe ...

  7. Intellij Idea 12 开发Android 报Caused by: java.lang.UnsatisfiedLinkError: FindLibrary return null;

    这次开发是用的百度地图api,导入两个so文件,结果启动的时候总是报Caused by: java.lang.UnsatisfiedLinkError: findlibrary return null ...

  8. [LeetCode OJ] Linked List Cycle II—Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  9. delete attempted to return null from a method with a primitive return type (int)

    今天被自己给蠢死了 今天在代码中遇到这个错误, 百度翻译一下:映射方法,从一org.system.mapper.child.chmorganizationexaminationmapper.delet ...

随机推荐

  1. C89_一些函数

    C89 string.h 中的函数: 复制函数 memcpy memmove strcpy strncpy 串接函数 strcat strncat 比较函数 memcmp strcmp strcoll ...

  2. Codeforces 877E - Danil and a Part-time Job(dfs序+线段树)

    877E - Danil and a Part-time Job 思路:dfs序+线段树 dfs序:http://blog.csdn.net/qq_24489717/article/details/5 ...

  3. Codeforces 595C - Warrior and Archer

    595C - Warrior and Archer 思路:设最后答案的区间为[l,r],那么r-l等于n/2,因为在(l,r)中的点都是其中一个人挖掉的,[0,l)和(r,n]中的点是另一个人挖掉的, ...

  4. 雷林鹏分享:C# 接口(Interface)

    C# 接口(Interface) 接口定义了所有类继承接口时应遵循的语法合同.接口定义了语法合同 "是什么" 部分,派生类定义了语法合同 "怎么做" 部分. 接 ...

  5. English trip -- VC(情景课)4 A Health

    Word doctor doctor's office medicine   [ˈmɛdɪsɪn]  n. 药:医学:内科:巫术  vt. 用药物治疗:给…用药 pill  n. 药丸 nurse   ...

  6. android--------根据文件路径加载指定文件

    Android根据指定的文件路径,加载该路径下指定文件格式(图片格式 png, gif,jpg jpeg)的文件相关信息的列表. 如图: public class MainActivity exten ...

  7. 牛客练习赛23-A/B/C/D/F

    https://www.nowcoder.com/acm/contest/156#question 链接:https://www.nowcoder.com/acm/contest/156/A来源:牛客 ...

  8. GDI+ DrawString字间距问题

    ///   <summary> ///   绘制任意间距文字 /// </summary> ///   <param   name= "text "& ...

  9. iOS UI-三种简单的动画设置

    一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView beginAnimations:nil context:nil]; //设置动画时长 ...

  10. javassist示例

    javassist的作用是动态生成字节码. package com.zhang; class Fighter {} public class Assist_Test { public static v ...