How to return NULL string
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的更多相关文章
- 你写的return null正确吗?
上次一篇“你写的try…catch真的有必要吗”引起了很多朋友的讨论.本次我在code review又发现了一个问题,那就是有人有意无意的写出了return null这样的代码,例如: public ...
- 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 ...
- java中,return和return null有什么区别吗?
java中,return和return null有什么区别吗? 最大的区别:return;方法的返回值必须是void!return null;方法的返回值必须不是 原始数据类型(封装类除过)和void ...
- 在Java中,return null 是否安全, 为什么?
Java代码中return value 为null 是不是在任何情况下都可以,为什么不会throw NullPointerException? Java语言层面:null值自身是不会引起任何问题的.它 ...
- 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 ...
- 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 ...
- Intellij Idea 12 开发Android 报Caused by: java.lang.UnsatisfiedLinkError: FindLibrary return null;
这次开发是用的百度地图api,导入两个so文件,结果启动的时候总是报Caused by: java.lang.UnsatisfiedLinkError: findlibrary return null ...
- [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 ...
- delete attempted to return null from a method with a primitive return type (int)
今天被自己给蠢死了 今天在代码中遇到这个错误, 百度翻译一下:映射方法,从一org.system.mapper.child.chmorganizationexaminationmapper.delet ...
随机推荐
- 【Python】Http Post请求四种请求体的Python实现
前言 前几天一个刚接触Python不深的朋友问我的Python的xml格式Post请求怎么发送,刚好最近也在学习Http请求相关的内容,所以决定总结一下各类Post请求的Python实现. Happy ...
- RPC 服务器不可用
1,查看“Remote Procedure Call (RPC)”启动2,设置下面选项.・Hyper-V服务器->虚拟交换机管理器,在虚拟交换机的[连接类型]下, 勾选[允许管理操作系统共享此网 ...
- 雷林鹏分享:C# 特性(Attribute)
C# 特性(Attribute) 特性(Attribute)是用于在运行时传递程序中各种元素(比如类.方法.结构.枚举.组件等)的行为信息的声明性标签.您可以通过使用特性向程序添加声明性信息.一个声明 ...
- TCP三次握手(待细研究)
xu言: 看到一张不错清晰的Tcp三次握手图,收藏 Initiator 发起人 Receiver 接收者 LISTENING 状态xx服务启动后首先处于侦听(LISTENING)状态. ESTAB ...
- LeetCode--203--删除链表中的节点
问题描述: 删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3 ...
- Intent在Activity之间传值的几种方式
发这篇博客主要讲一下Android中Intent中如何传值的几种方法: 1:基本数据类型,包含了Java八种基本数据类型和CharSequece文本2:八种数据类新对应数组和CharSequece文本 ...
- hihoCoder-1087 Hamiltonian Cycle (记忆化搜索)
描述 Given a directed graph containing n vertice (numbered from 1 to n) and m edges. Can you tell us h ...
- 隔离级别 && SNAPSHOT
read uncommitted | 0 未提交读 将查询的隔离级别指定为 0. 可以读脏数据. 读脏数据:一事务对数据进行了增删改,但未提交,有可能回滚,另一事务却读取了未提交的数据. 例: 公 ...
- Erlang:Error in process ... with exit value
=ERROR REPORT==== 10-Apr-2015::16:30:04 ===Error in process <0.218.0> with exit value: {badarg ...
- CentOS7系统更换YUM Repo源
CentOS7系统更换YUM Repo源 备份原镜像 sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.re ...