收集、管理和分享有用的代码片段,提高开发效率
unique_ptr使用示例
#include <memory>
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass() { cout << "Constructor\n"; }
~MyClass() { cout << "Destructor\n"; }
};
int main() {
unique_ptr<MyClass> ptr( new MyClass() );
return 0;
}
MySQL事务处理示例
START TRANSACTION;
UPDATE accountSET balance = balance - 100 WHERE id = 1;
UPDATE account SET balance = balance + 100 WHERE id = 2;
COMMIT;
-- If error occurs:
ROLLBACJ;
处理文件上传表单
🔥
Scikit-learn线性回归
from sklearn.linear_model import LinearRegression
# Sample data
X = [[1], [2], [3], [4]]
y = [1, 2, 3, 4]
# Create and train model
model = LinearRegression().fit(X, )
# Predict
prediction = model.predict([[5]])
print(prediction)
ExecutorService使用
import java.util.concurrent.*;
public class ThreadPoolExample {
public static void main(String[] args) {
ExecutorService eservice = Executors.newFixedThreadPool(4);
for (int i = 0; i < 10; i++) {
eservice.submit(() -> {
System.out.println("Task " + i + " executed by " + Thread.currentThread().getName());
});
}
eservice.shutdown();
}
}
Lambda函数示例
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> nums = {1, 2, 3, 4, 5};
// Square each number using lambda
for_each(nums.begin(), nums.end(), [](int &n) {
n = n * n;
});
// Display results
for (auto n : nums) {
cout << n << " ";
}
return 0;
}
高效管理您的代码片段,提高开发效率
通过关键字、语言或分类快速查找代码片段,支持模糊搜索和过滤功能
支持多种编程语言的语法高亮,使代码更加清晰易读
随时随地访问您的代码片段库,支持桌面和移动设备
浏览最受欢迎的代码分类