考虑 Linux 系统上的以下两个文件:
使用消息.cpp
#include <iostream>
extern const char* message;
void print_message();
int main() {
std::cout << message << '\n';
print_message();
}
Run Code Online (Sandbox Code Playgroud)
libmessage.cpp
#include <iostream>
const char* message = "Meow!"; // 1. absolute address of string literal
// needs runtime relocation in a .so
void print_message() {
std::cout << message << '\n';
}
Run Code Online (Sandbox Code Playgroud)
我们可以将use_message.cpp编译为目标文件,将libmessage.cpp编译为共享库,并将它们链接在一起,如下所示:
$ g++ use_message.cpp -c -pie -o use_message.o
$ g++ libmessage.cpp -fPIC -shared -o libmessage.so
$ g++ use_message.o libmessage.so -o use_message
Run Code Online (Sandbox Code Playgroud)
的定义message …
为了更好地使用 Lisp,我遇到了以下问题:
(defun countVowels (string)
(setf vowels (list 'a 0 'e 0 'i 0 'o 0 'u 0))
(loop for ch across string
when (member ch vowels)
do (incf (getf vowels ch)))
(format t "~{~a~^, ~}" vowels))
Run Code Online (Sandbox Code Playgroud)
在我看来,这是通过增加 plist 来计算每个元音的。但是,当我用例如调用该函数时
(countVowels "test")
Run Code Online (Sandbox Code Playgroud)
输出是
A, 0, E, 0, I, 0, O, 0, U, 0
Run Code Online (Sandbox Code Playgroud) 我有以下数据框:
\ndf = pl.DataFrame({\n "Column A": [2, 3, 1, 4, 1, 3, 3, 2, 1, 0],\n "Column B": [\n "Life", None, None, None, "Death", None, \n "Life", None, None, "Death"\n ]\n})\nRun Code Online (Sandbox Code Playgroud)\nshape: (10, 2)\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 Column A \xe2\x94\x86 Column B \xe2\x94\x82\n\xe2\x94\x82 --- \xe2\x94\x86 --- \xe2\x94\x82\n\xe2\x94\x82 i64 \xe2\x94\x86 str \xe2\x94\x82\n\xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xaa\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1\n\xe2\x94\x82 2 \xe2\x94\x86 Life \xe2\x94\x82\n\xe2\x94\x82 3 \xe2\x94\x86 null \xe2\x94\x82\n\xe2\x94\x82 1 \xe2\x94\x86 null \xe2\x94\x82\n\xe2\x94\x82 4 \xe2\x94\x86 null \xe2\x94\x82\n\xe2\x94\x82 1 \xe2\x94\x86 Death \xe2\x94\x82\n\xe2\x94\x82 3 \xe2\x94\x86 null \xe2\x94\x82\n\xe2\x94\x82 3 \xe2\x94\x86 Life \xe2\x94\x82\n\xe2\x94\x82 2 \xe2\x94\x86 …Run Code Online (Sandbox Code Playgroud) 我有一个 lambda 表达式如下:
var obj = data.FirstOrDefault(x => x.id == id && x.city == city.ToLower());
Run Code Online (Sandbox Code Playgroud)
数据是一个列表
我怎样才能做到忽略大小写?
我正在使用 qbraid 的 qiskit 教程,这是一个基本的 hello world。我发现可以使用其他量子后端而不是 qiskit,但用户界面中没有明确的路径。
是否有命令行或直接方式来搜索其他后端的 API?
标题描述了我的问题。我现在感觉真的很愚蠢,因为这可能是一个小问题。
我已经被这个问题困扰了快两天了。我正在构建的应用程序要大得多,使用 docker compose 来启动 postgres 容器,但是可以通过创建一个新的(java 21,maven)spring boot 项目(仅使用 spring web 作为其依赖项)来重新创建问题。在带有@SpringBootApplication的类中,添加以下内容:
@Bean
ApplicationRunner applicationRunner() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
return args -> {
System.out.println("Parsed: 12:30 pm -> " + LocalTime.parse("12:30 p.m.", formatter));
};
}
Run Code Online (Sandbox Code Playgroud)
当我使用 intellij 或 运行它时./mvnw spring-boot:run,或者在常规 java 类(没有注释)中运行它时,它会运行。
但是,当我使用这个 docker 文件时:
FROM eclipse-temurin:21-jdk-alpine
COPY . /app/
WORKDIR /app
CMD ["./mvnw", "spring-boot:run", "-Dskiptests"]
Run Code Online (Sandbox Code Playgroud)
并使用 构建docker build -t localtime:1.0 .,然后使用: 运行docker run -p 1234:8080 --name localtime-container localtime:1.0。这是我在常规春季启动日志消息后得到的信息:
Error starting ApplicationContext. …Run Code Online (Sandbox Code Playgroud) 如何检查两个函数签名是否属于同一类型。这是我尝试过但没有编译
#include <iostream>
#include <type_traits>
#include <functional>
struct Employee {
int id;
int age;
Employee(const int id, const int age) {
this->id = id;
this->age = age;
}
void print() const {
std::cout << "ID: " << id << ", AGE: " << age << std::endl;
}
};
template<typename T, typename Comp>
const T& get_min_emp(const T& a, const T& b, Comp comp) {
static_assert(std::is_same<Comp, bool(*)(const T&, const T&)>::value, "invalid comparator");
return comp(a, b) ? a : b;
}
int main() …Run Code Online (Sandbox Code Playgroud) 下面是一道考试题。+++=看起来很奇怪,所以我问 MS Copilot,它一直说它无效,而 Google Gemini 说它可能有效,但未定义。有效*pt +++= 20;并保证与*pt++ += 20;
#include <stdio.h>
void main()
{
int num[4] = {1, 2, 3, 4};
int *pt = num;
pt++;
*pt++ = 5;
*pt ++= 10;
pt--;
*pt +++= 20;
printf("%d %d %d %d", num[0], num[1], num[2], num[3]);
}
Run Code Online (Sandbox Code Playgroud)
考试的答案是“1 5 30 4”,我在电脑上运行代码时也是这样。
在 Kotlin 中,我们可以像这样使用 Elvis 运算?:符:
val string: String = null ?: "something else"
Run Code Online (Sandbox Code Playgroud)
但是如果“其他东西”是计算的结果呢,比如
val string: String = null ?: {
// do some comutations here
"something else"
}
Run Code Online (Sandbox Code Playgroud)
这不会编译,因为 is 的右侧?:是一个函数() => String而不是String。
我有一种感觉,我需要使用其中一个函数等takeIf,takeUnless但我不明白。
谢谢
c++ ×2
abi ×1
aws-lambda ×1
c ×1
c# ×1
common-lisp ×1
docker ×1
elf ×1
java ×1
kotlin ×1
lisp ×1
python ×1
qbraid ×1
qiskit ×1
relocation ×1
spring-boot ×1