#include <stdio.h>
int main(int argc, char** argv) {
int num = 0;
printf("Input: ");
scanf("%d", &num); <<<
printf("%d\n", num);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
scanf("%d", #);
Clang-Tidy: 'scanf' 用于将字符串转换为整数值,但函数不会报告转换错误;考虑使用“strtol”代替
我用 CLion 编写了一个非常简单的代码,它推荐我使用“strtol”而不是“scanf”。
但我只使用整数变量,没有字符串。我不明白为什么弹出检查消息。
如何修改此代码?
这是map()方法的实现:
public <U> Optional<U> map(Function<? super T, ? extends U> mapper) {
Objects.requireNonNull(mapper);
if (!isPresent()) {
return empty();
} else {
return Optional.ofNullable(mapper.apply(value));
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样打电话时map(),T和U?的类型是什么?wildcard(?)的类型是什么?这非常令人困惑.
Optional<String> os1 = Optional.of("Optional String");
Optional<String> os2 = os1.map(s -> s.toUpperCase());
Run Code Online (Sandbox Code Playgroud)
Javadoc声明说:
@param
<U>是映射函数返回的值的类型.
" 映射函数 "是指map()方法还是参数map()?
ElasticSearch(2.4.6) 服务在 Windows 上始终无法启动。
[2019-02-01 12:27:59] [info] [14564] Starting service...
[2019-02-01 12:27:59] [error] [15256] CreateJavaVM Failed
[2019-02-01 12:27:59] [error] [15256] The system cannot find the file specified.
[2019-02-01 12:27:59] [error] [14564] Failed to start Java
[2019-02-01 12:27:59] [error] [14564] ServiceStart returned 4
Run Code Online (Sandbox Code Playgroud)
我使用的是 Java 10,但 ElasticSearch 2.4.6 不支持 Java 9+,因此我在文件中手动设置了 Java 8 JRE 的elasticsearch.bat路径service.bat。
...
set JAVA_HOME=C:\Program Files\Java\jre1.8.0_191
...
Run Code Online (Sandbox Code Playgroud)
启动 ES 二进制文件并将 ES 安装为服务时没有问题,但“启动”该服务目前是不可能的。
我该如何解决这个问题?我也在使用 Haystack,它仅支持 ElasticSearch 1.x 和 2.x,所以我无法升级 ElasticSearch 的版本。
就我而言,默认的“包装缩进”大小始终为 4 个空格。
我想改变这个尺寸。我该如何配置?
def post(self):
if db.users.find({"email": email}).count() != 0:
abort(400, message="email is alread used.")
Run Code Online (Sandbox Code Playgroud)
DeprecationWarning:不建议使用count。请改用Collection.count_documents。
我正在使用Python-Flask和PyMongo软件包制作身份验证服务器。每次post()调用方法时,都会显示以上弃用警告消息。
def post(self):
if db.users.find({"email": email}).count_documents() != 0:
abort(400, message="email is alread used.")
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改count()为,则会出现count_documents()以下错误消息。
AttributeError:“游标”对象没有属性“ count_documents”
呼叫count_documents()后如何正确find()呼叫?
#include <array>
int value1(int param) {
return param * 2;
}
constexpr int value2(int param) {
return param * 2;
}
int main() {
const int i = 10;
std::array<int, value1(i)> starr1 = {}; // 1
std::array<int, value2(i)> starr2 = {}; // 2
return 0;
}
Run Code Online (Sandbox Code Playgroud)
2可以,但是1由于std::array必须制作静态大小数组,因此会产生编译错误。value2()由于constexpr关键字而返回编译时常量值。
那么,编译器如何推断出value2(i)编译时常数呢?value2()编译时会调用函数吗?
const int value1(int param) {
return param * 2;
}
int main() {
const int i = 10;
std::array<int, …Run Code Online (Sandbox Code Playgroud) #include <iostream>
class MemoryBlock {
private:
int length = 0;
int* m_arr = nullptr;
public:
// Constructor
explicit MemoryBlock(int p_length) : length(p_length), m_arr(new int[length]) {
std::cout << "In MemoryBlock(int), length is " << length << ".\n";
}
// Destructor
~MemoryBlock() {
std::cout << "~MemoryBlock() is called. Deleting resources.\n";
delete[] m_arr;
}
// Copy constructor
MemoryBlock(const MemoryBlock& other) : length(other.length), m_arr(new int[other.length]) {
std::cout << "In MemoryBlock(const MemoryBlock&), length is " << length << ".\n";
for (int i = 0; i …Run Code Online (Sandbox Code Playgroud) +-----------+----------+------------+----------------------------+----------------------------+-----------------------+
| Name | Owner | Encoding | Collate | Ctype | Access privileges |
|-----------+----------+------------+----------------------------+----------------------------+-----------------------|
| postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 | <null> |
| template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres |
| | | | | | postgres=CTc/postgres |
| template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres |
| | | | | | postgres=CTc/postgres |
+-----------+----------+------------+----------------------------+----------------------------+-----------------------+
Run Code Online (Sandbox Code Playgroud)
Collate和的值 …
class Vtx {
private:
int indexPoint;
int radius;
std::string strName;
public:
Vtx(const int p_indexPoint, const int p_radius, std::string p_strName)
: indexPoint(p_indexPoint),
radius(p_radius),
strName(std::move(p_strName)) {
std::cout << "Constructor\n";
}
Vtx(const Vtx& rhs)
: indexPoint(rhs.indexPoint),
radius(rhs.radius),
strName(rhs.strName) {
std::cout << "Copy constructor\n";
}
// (#)
Vtx(const Vtx&& rhs)
: indexPoint(rhs.indexPoint),
radius(rhs.radius),
strName(rhs.strName) {
std::cout << "Move constructor\n";
}
~Vtx() {
std::cout << "Destructor\n";
}
};
Run Code Online (Sandbox Code Playgroud)
对于这段代码,clang-tidy 给了我以下警告消息。
我无法理解何时在移动构造函数内部调用复制构造函数。(#)虽然编译效果很好,但我想删除这个警告。我该如何修复它?