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 ...
随机推荐
- Struts2文件上传的大小限制问题
问题:上传大文件报错…… 解决:修改struts.xml文件中的参数如下 <constant name="struts.multipart.maxSize" value= ...
- fragment 小结
1:注意事项 3.0以前的Android 版本要使用FragmentActivity 来装载Fragment ,使用到support v4包. 3.0以后的版本可以直接在Activity里面添 ...
- Codeforces 899E - Segments Removal
899E - Segments Removal 思路:priority_queue+pair 代码: #include<bits/stdc++.h> using namespace std ...
- 关于React性能优化
这几天陆陆续续看了一些关于React性能优化的博客,大部分提到的都是React 15.3新加入的PureComponent ,通过使用这个类来减少React的重复渲染,从而提升页面的性能.使用过Rea ...
- Analysis of single cell RNA-seq data(单细胞终极课程)
业界良心啊,开源的单细胞课程. 随便看了几章,课程写得非常用心,非常适合新手. 课程地址:Analysis of single cell RNA-seq data 源码地址:hemberg-lab/s ...
- 利用Py-Socket模块做的一个不登陆windows服务器自动实现替换或者调用自动拨号功能
xu言: 最近,有个朋友让我帮忙“搞点事情”,然后正好在学习socket模块,这个模块666啊,基本上可以实现远程服务器cmd shell的大部分功能.好,话不多说,直接上码~ 由于很多电信运营商都会 ...
- hdu6394Tree lct
树上弹飞绵羊,现场树分块没写出来= = 先预处理倍增,新建一个n+1节点,能弹到就建一条边,然后每操作2就cut,然后link,1的答案就是x到n+1的距离, //#pragma GCC optimi ...
- Bata验收互评
小组的名字和链接 优点 缺点,bug报告 最终名次 编程题全队 ①限制用户重复注册同一个邮箱②注册之后可以弹出用户名,不用手动输入③细节考虑到位④面板可拖动,增删改查,还能添加成员 Q1:程序有什么具 ...
- python daal test
import os import sys from daal.algorithms import low_order_moments from daal.data_management import ...
- tensoflow学习入门一
对于如何创建图并开启session,参考如下 # -- encoding:utf-8 -- import tensorflow as tf # 定义常量矩阵a和矩阵b a=tf.constant([[ ...