c++ - Getting Unchecked return value from library?
问题描述
Calling remove(file.txt) without checking return value. This library function may fail and return an error code
I am getting above warning in below code-
bool chkfile() {
std::remove(file.txt);
return true;
}
How should I remove this warning?
解决方案
You can refer to this link to see the issue. You have to check if there is no issue during remove operation.
Your code should be something like this,
bool chkfile() {
if (std::remove("file.txt") != 0) {
// error handling
} else {
// success
return true;
}
}
推荐阅读
- jms - Logstash-Plug in-JMS 和 Weblogic 12.2.1 的问题
- python - 有没有办法清理这个结构?
- visual-studio-code - 使用两种不同类型的代码格式化文件
- angular - 使用 Firebase 用户管理添加额外字段
- asp.net-core - asp.net core 如何在运行时从实体框架更改连接字符串(登录后)
- python - 如何根据匹配列从另一个df创建列?
- docker - 使用 Weave Net Docker Swarm Adapter 允许服务通信
- node.js - 获取请求到本地基本 URL
- javascript - VUE.JS - 如何在 vue.js 的 javascript 文件中使用 vue.js 之外的类?
- c# - Xamarin Forms 在 CollectionView 中设置特定值