当前位置: 首页 > news >正文

【Qt快速入门(六)】- QLineEdit按钮的使用

目录

  • Qt快速入门(六)- QLineEdit按钮的使用
    • QLineEdit按钮的使用
      • QLineEdit的基本用法
        • 1. 创建和设置文本
        • 2. 获取输入文本
        • 3. 清空输入文本
      • 文本处理
        • 1. 选择文本
        • 2. 设置光标位置
        • 3. 撤销和重做
      • 输入验证
        • 1. 输入掩码
        • 2. 校验器
        • 3. 输入限制
      • 样式设置
        • 1. 设置字体和颜色
        • 2. 占位符文本
        • 3. 密码输入
      • 信号与槽机制
        • 1.文本变化信号
        • 2. 编辑完成信号
      • 扩展功能
        • 1. 自动完成
        • 2. 上下文菜单
      • 总结

Qt快速入门(六)- QLineEdit按钮的使用

QLineEdit按钮的使用

QLineEdit是Qt框架中用于文本输入的单行输入控件。它提供了丰富的功能,包括文本输入、文本验证、占位符提示、密码输入等。本文将详细讲解QLineEdit的使用,包括其基本用法、文本处理、输入验证、样式设置、信号与槽机制、扩展功能以及在Qt Designer中的使用。

QLineEdit的基本用法

QLineEdit控件可以通过Qt Designer设计界面,也可以通过代码动态创建和设置。以下是一些常见的用法示例。

1. 创建和设置文本

QLineEdit可以通过构造函数创建,并使用setText方法设置初始文本。

#include <QApplication>
#include <QLineEdit>int main(int argc, char *argv[]) {QApplication app(argc, argv);QLineEdit lineEdit;lineEdit.setText("Hello, World!");lineEdit.show();return app.exec();
}

在这个简单示例中,QLineEdit被创建并设置了初始文本“Hello, World!”。show方法用于显示控件。

2. 获取输入文本

可以使用text方法获取QLineEdit中的文本。

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QMessageBox>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;QPushButton button("Show Text");layout.addWidget(&lineEdit);layout.addWidget(&button);QObject::connect(&button, &QPushButton::clicked, [&lineEdit]() {QMessageBox::information(nullptr, "Text", "You entered: " + lineEdit.text());});window.show();return app.exec();
}

在这个示例中,当按钮被点击时,会弹出一个消息框,显示QLineEdit中的文本。

3. 清空输入文本

可以使用clear方法清空QLineEdit中的文本。

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;QPushButton button("Clear Text");layout.addWidget(&lineEdit);layout.addWidget(&button);QObject::connect(&button, &QPushButton::clicked, [&lineEdit]() {lineEdit.clear();});window.show();return app.exec();
}

在这个示例中,当按钮被点击时,QLineEdit中的文本会被清空。

文本处理

QLineEdit提供了多种方法处理文本输入,包括选择文本、设置光标位置、撤销和重做等。

1. 选择文本

可以使用selectAll方法选择QLineEdit中的所有文本,使用setSelection方法选择特定范围的文本。

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;lineEdit.setText("Hello, World!");QPushButton selectButton("Select All");QPushButton partialSelectButton("Select Partial");layout.addWidget(&lineEdit);layout.addWidget(&selectButton);layout.addWidget(&partialSelectButton);QObject::connect(&selectButton, &QPushButton::clicked, [&lineEdit]() {lineEdit.selectAll();});QObject::connect(&partialSelectButton, &QPushButton::clicked, [&lineEdit]() {lineEdit.setSelection(7, 5);  // Select "World"});window.show();return app.exec();
}

在这个示例中,按钮分别用于选择QLineEdit中的所有文本和部分文本。

2. 设置光标位置

可以使用setCursorPosition方法设置光标位置,使用cursorPosition方法获取当前光标位置。

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;lineEdit.setText("Hello, World!");QPushButton cursorButton("Set Cursor Position");QLabel cursorPositionLabel("Cursor Position: 0");layout.addWidget(&lineEdit);layout.addWidget(&cursorButton);layout.addWidget(&cursorPositionLabel);QObject::connect(&cursorButton, &QPushButton::clicked, [&lineEdit, &cursorPositionLabel]() {lineEdit.setCursorPosition(5);  // Set cursor position after "Hello"cursorPositionLabel.setText("Cursor Position: " + QString::number(lineEdit.cursorPosition()));});window.show();return app.exec();
}

在这个示例中,按钮用于设置光标位置,并显示当前光标位置。

3. 撤销和重做

可以使用undo和redo方法实现文本输入的撤销和重做功能。

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;QPushButton undoButton("Undo");QPushButton redoButton("Redo");layout.addWidget(&lineEdit);layout.addWidget(&undoButton);layout.addWidget(&redoButton);QObject::connect(&undoButton, &QPushButton::clicked, [&lineEdit]() {lineEdit.undo();});QObject::connect(&redoButton, &QPushButton::clicked, [&lineEdit]() {lineEdit.redo();});window.show();return app.exec();
}

在这个示例中,按钮用于撤销和重做文本输入操作。

输入验证

QLineEdit支持多种输入验证方式,包括输入掩码、校验器和输入限制。

1. 输入掩码

可以使用setInputMask方法设置输入掩码,以限制用户输入的格式。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit phoneLineEdit;phoneLineEdit.setInputMask("(999) 999-9999");  // Phone number masklayout.addWidget(&phoneLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为电话号码输入掩码,只允许用户输入指定格式的电话号码。

2. 校验器

可以使用QValidator类或其子类(如QIntValidator、QDoubleValidator和QRegExpValidator)设置输入校验器。

#include <QApplication>
#include <QLineEdit>
#include <QIntValidator>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit intLineEdit;QIntValidator intValidator(0, 100);  // Only allow integers between 0 and 100intLineEdit.setValidator(&intValidator);layout.addWidget(&intLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为只允许输入0到100之间的整数。

3. 输入限制

可以使用setMaxLength方法限制QLineEdit的最大输入长度,使用setReadOnly方法将QLineEdit设置为只读。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit limitedLineEdit;limitedLineEdit.setMaxLength(10);  // Limit input length to 10 charactersQLineEdit readOnlyLineEdit;readOnlyLineEdit.setText("Read-Only Text");readOnlyLineEdit.setReadOnly(true);  // Set to read-onlylayout.addWidget(&limitedLineEdit);layout.addWidget(&readOnlyLineEdit);window.show();return app.exec();
}

在这个示例中,第一个QLineEdit被限制为最多输入10个字符,第二个QLineEdit被设置为只读。

样式设置

QLineEdit支持丰富的样式设置,包括字体、颜色、背景等。以下是一些常见的样式设置方法。

1. 设置字体和颜色

可以使用setFont方法设置QLineEdit的字体,使用setStyleSheet方法设置颜色和其他样式。

#include <QApplication>
#include <QLineEdit>
#include <QFont>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit styledLineEdit;QFont font("Arial", 14, QFont::Bold);styledLineEdit.setFont(font);styledLineEdit.setStyleSheet("color: blue; background-color: yellow;");layout.addWidget(&styledLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为Arial字体、14号、加粗,文本颜色为蓝色,背景颜色为黄色。

2. 占位符文本

可以使用setPlaceholderText方法设置QLineEdit的占位符文本,提示用户输入内容。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit placeholderLineEdit;placeholderLineEdit.setPlaceholderText("Enter your name...");layout.addWidget(&placeholderLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为显示占位符文本“Enter your name…”。

3. 密码输入

可以使用setEchoMode方法设置QLineEdit为密码输入模式,以隐藏用户输入的内容。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit passwordLineEdit;passwordLineEdit.setEchoMode(QLineEdit::Password);layout.addWidget(&passwordLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为密码输入模式,用户输入的内容将以星号(*)显示。

信号与槽机制

QLineEdit提供了多种信号,用于处理文本变化、编辑完成等事件。

1.文本变化信号

textChanged和textEdited信号用于处理文本变化事件。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;QLabel textChangedLabel("Text Changed: ");QLabel textEditedLabel("Text Edited: ");layout.addWidget(&lineEdit);layout.addWidget(&textChangedLabel);layout.addWidget(&textEditedLabel);QObject::connect(&lineEdit, &QLineEdit::textChanged, [&textChangedLabel](const QString &text) {textChangedLabel.setText("Text Changed: " + text);});QObject::connect(&lineEdit, &QLineEdit::textEdited, [&textEditedLabel](const QString &text) {textEditedLabel.setText("Text Edited: " + text);});window.show();return app.exec();
}

在这个示例中,textChanged信号在文本变化时触发,textEdited信号在用户编辑文本时触发。

2. 编辑完成信号

editingFinished信号在用户完成编辑并按下回车键或失去焦点时触发。

#include <QApplication>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit lineEdit;QLabel editingFinishedLabel("Editing Finished: ");layout.addWidget(&lineEdit);layout.addWidget(&editingFinishedLabel);QObject::connect(&lineEdit, &QLineEdit::editingFinished, [&lineEdit, &editingFinishedLabel]() {editingFinishedLabel.setText("Editing Finished: " + lineEdit.text());});window.show();return app.exec();
}

在这个示例中,editingFinished信号在用户完成编辑时触发,并显示编辑完成后的文本。

扩展功能

QLineEdit还支持一些扩展功能,如自动完成和上下文菜单。

1. 自动完成

可以使用QCompleter类实现QLineEdit的自动完成功能。

#include <QApplication>
#include <QLineEdit>
#include <QCompleter>
#include <QStringList>
#include <QVBoxLayout>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);QLineEdit autoCompleteLineEdit;QStringList wordList = {"apple", "banana", "cherry", "date", "fig", "grape"};QCompleter completer(wordList);autoCompleteLineEdit.setCompleter(&completer);layout.addWidget(&autoCompleteLineEdit);window.show();return app.exec();
}

在这个示例中,QLineEdit被设置为支持自动完成,用户输入时会显示匹配的单词列表。

2. 上下文菜单

可以通过继承QLineEdit并重写contextMenuEvent方法自定义上下文菜单。

#include <QApplication>
#include <QLineEdit>
#include <QMenu>
#include <QVBoxLayout>
#include <QWidget>class CustomLineEdit : public QLineEdit {Q_OBJECTpublic:CustomLineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {}protected:void contextMenuEvent(QContextMenuEvent *event) override {QMenu *menu = createStandardContextMenu();menu->addAction("Custom Action", this, SLOT(customAction()));menu->exec(event->globalPos());delete menu;}private slots:void customAction() {setText("Custom Action Triggered");}
};int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;QVBoxLayout layout(&window);CustomLineEdit customLineEdit;layout.addWidget(&customLineEdit);window.show();return app.exec();
}#include "main.moc"

在这个示例中,QLineEdit被继承并添加了一个自定义的上下文菜单项。

总结

QLineEdit是Qt框架中功能强大且灵活的单行文本输入控件。通过详细了解QLineEdit的基本用法、文本处理、输入验证、样式设置、信号与槽机制、扩展功能以及在Qt Designer中的使用,开发者可以在实际项目中充分利用QLineEdit的优势,构建出丰富多样的用户界面。无论是简单的文本输入、复杂的格式验证还是自定义样式的高级输入框,QLineEdit都能满足开发者的需求,使得应用程序更加友好和易用。

相关文章:

【Qt快速入门(六)】- QLineEdit按钮的使用

目录 Qt快速入门&#xff08;六&#xff09;- QLineEdit按钮的使用QLineEdit按钮的使用QLineEdit的基本用法1. 创建和设置文本2. 获取输入文本3. 清空输入文本 文本处理1. 选择文本2. 设置光标位置3. 撤销和重做 输入验证1. 输入掩码2. 校验器3. 输入限制 样式设置1. 设置字体和…...

常用损失函数详解:广泛使用的优化约束方法

各类常用损失函数详解&#xff1a;广泛使用的优化约束方法 今天介绍下损失函数&#xff0c;先介绍下我常用的方法SmoothedL1&#xff0c;它是一个平滑的L1 penalty函数,用于处理约束violation。 标准的L1 penalty函数定义为: L 1 ( x ) { 0 , if x ≤ 0 x , if x > 0 …...

鸿蒙开发组件:【创建DataAbility】

创建DataAbility 实现DataAbility中Insert、Query、Update、Delete接口的业务内容。保证能够满足数据库存储业务的基本需求。BatchInsert与ExecuteBatch接口已经在系统中实现遍历逻辑&#xff0c;依赖Insert、Query、Update、Delete接口逻辑&#xff0c;来实现数据的批量处理。…...

配电室数据中心巡检3d可视化搭建的详细步骤

要搭建配电室巡检的3D可视化系统&#xff0c;可以按照以下步骤进行&#xff1a; 收集配电室数据&#xff1a; 首先&#xff0c;需要收集配电室的相关数据&#xff0c;包括配电室的布局、设备信息、传感器数据等。可以通过实地调查、测量和设备手册等方式获取数据。 创建3D模型…...

TIME_WAIT的危害

前言 该文章主要讨论下TIME_WAIT的存在意义和潜在危害&#xff0c;以及解决措施。 具体内容 首先看一下下面这幅图 这幅图来自《TCP IP详解卷1&#xff1a;协议 原书第2版中文》TCP状态变迁图。 TIME_WAIT存在意义 可靠的终止TCP连接。 保证让迟来的TCP报文有足够的时间被…...

搜维尔科技邀您共赴2024第四届轨道车辆工业设计国际研讨会

会议内容 聚焦“创新、设计、突破”&#xff0c;围绕“面向生命健康、可持续发展的轨道交通系统” 为主题&#xff0c;从数字化、智能化、人性化、绿色发展等方面&#xff0c;探索轨道交通行业的设计新趋势及发展新机遇。 举办时间 2024年7月10日-12日 举办地点 星光岛-青岛融…...

智能中人类造成的风险、机器造成的风险、环境造成的风险

在使用智能技术时&#xff0c;可能会面临各种类型的风险。以下是一些可能的风险情况&#xff1a; 1、人类造成的风险 错误判断和决策&#xff1a;人类在使用智能系统时可能会因为各种原因做出错误的判断和决策&#xff0c;导致不良后果。人为错误&#xff1a;技术操作人员、维护…...

MYSQL基础查询

示例&#xff1a;user_profile iddevice_idgenderageuniversityprovince12138male21北京大学Beijing23214male复旦大学Shanghai36543female20北京大学Beijing42315female23浙江大学Zhejiang55432male25山东大学Shandong 查询所有列 select * from user_profile&#xff1b;查询…...

【Golang】Go 中的生产者-消费者模式

Go 中的生产者-消费者模式 来源:https://medium.com/@mm.nikfarjam/the-producer-consumer-pattern-in-go-cf97299a0320 文章目录 Go 中的生产者-消费者模式介绍关键组件在 Go 中的实现结论Go 中的生产者-消费者模式 介绍 生产者-消费者模式是处理大数据的最常见设计模式之一…...

【通过新能源汽车的智慧数字底盘技术看计算机的相关技术堆栈?以后是软硬结合的全能程序员的天下,取代全栈(前后端都会的全栈程序员)】

汽车的“智慧数字底盘”是一个综合性的技术平台&#xff0c;旨在提升车辆的性能、安全性和驾驶体验。它集成了多种先进的技术和系统&#xff0c;是全能程序员的必杀技&#xff01; 1. 传感器技术 a. 激光雷达&#xff08;LiDAR&#xff09; 用于生成高分辨率的3D地图&#…...

Python网络爬虫4-实战爬取pdf

1.需求背景 爬取松产品中心网站下的家电说明书。这里以冰箱为例&#xff1a;松下电器-冰箱网址 网站分析&#xff1a; 第一步&#xff1a; 点击一个具体的冰箱型号&#xff0c;点击了解更多&#xff0c;会打开此型号电器的详情页面。 第二步&#xff1a;在新打开的详情页面中…...

超神级!Markdown最详细教程,程序员的福音

超神级&#xff01;Markdown最详细教程&#xff0c;程序员的福音Markdown最详细教程&#xff0c;关于Markdown的语法和使用就先讲到这里&#xff0c;如果喜欢&#xff0c;请关注“IT技术馆”。馆长会更新​最实用的技术&#xff01;https://mp.weixin.qq.com/s/fNzhLFyYRd3skG-…...

Android OTA 升级基础知识详解+源码分析

前言&#xff1a; 本文仅仅对OTA升级的几种方式的概念和运用进行总结&#xff0c;仅在使用层面对其解释。需要更详细的内容我推荐大神做的全网最详细的讲解&#xff1a; https://blog.csdn.net/guyongqiangx/article/details/129019303?spm1001.2014.3001.5502 三种升级方式…...

【吊打面试官系列-Mysql面试题】SQL 语言包括哪几部分?每部分都有哪些操作关键字?

大家好&#xff0c;我是锋哥。今天分享关于 【SQL 语言包括哪几部分&#xff1f;每部分都有哪些操作关键字&#xff1f;】面试题&#xff0c;希望对大家有帮助&#xff1b; SQL 语言包括哪几部分&#xff1f;每部分都有哪些操作关键字&#xff1f; SQL 语言包括数据定义(DDL)、…...

Redis的缓存击穿与解决

缓存击穿问题也叫热点Key问题&#xff0c;就是一个被高并发访问并且缓存重建业务较复杂的Key突然失效了&#xff0c;无数的请求访问会在瞬间给数据库带来巨大的冲击。 Redis实战篇 | Kyles Blog (cyborg2077.github.io) 目录 解决方案 互斥锁 实现 逻辑过期 实现 解决方案…...

网络层 IP协议【计算机网络】【协议格式 || 分片 || 网段划分 || 子网掩码】

博客主页&#xff1a;花果山~程序猿-CSDN博客 文章分栏&#xff1a;Linux_花果山~程序猿的博客-CSDN博客 关注我一起学习&#xff0c;一起进步&#xff0c;一起探索编程的无限可能吧&#xff01;让我们一起努力&#xff0c;一起成长&#xff01; 目录 一&#xff0c;前提 二&…...

Python学习笔记14:进阶篇(三)。类的终结篇,类的导入和模块的导入。

前言 这篇文章属于类知识的最后一篇&#xff0c;带一点点其他知识&#xff0c;学习内容来自于Python crash course。 关注我私信发送Python crash course&#xff0c;分享一份中文版PDF。 类的导入 在学习的时候&#xff0c;包括之前&#xff0c;我都是在一个文件中把所有代…...

C++ lambda表达式举例

C lambda表达式 Lambda表达式是一种简洁的方式来创建匿名函数&#xff0c;可以直接在函数调用的地方定义&#xff0c;主要用于简化代码。 Lambda表达式的基本语法如下&#xff1a; [capture](parameters) -> return_type {// function body };示例1&#xff1a;基本用法 …...

持续总结中!2024年面试必问 20 道设计模式面试题(五)

上一篇地址&#xff1a;持续总结中&#xff01;2024年面试必问 20 道设计模式面试题&#xff08;四&#xff09;-CSDN博客 九、请解释代理模式&#xff08;Proxy Pattern&#xff09;及其类型。 代理模式&#xff08;Proxy Pattern&#xff09;是一种结构设计模式&#xff0c…...

嵌入式面经111题答案汇总(含技术答疑)_嵌入式项目源码分享

111道嵌入式面试题答案汇总专栏链接&#xff08;承诺免费技术答疑&#xff09; --> 《嵌入式/C面试题解析大全》 1、简介 本人是2020年毕业于广东工业大学研究生&#xff1a;许乔丹&#xff0c;有国内大厂CVTE和世界500强企业工作经验&#xff0c;整理超全面111道嵌入式面试…...

零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?

一、核心优势&#xff1a;专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发&#xff0c;是一款收费低廉但功能全面的Windows NAS工具&#xff0c;主打“无学习成本部署” 。与其他NAS软件相比&#xff0c;其优势在于&#xff1a; 无需硬件改造&#xff1a;将任意W…...

【JVM】- 内存结构

引言 JVM&#xff1a;Java Virtual Machine 定义&#xff1a;Java虚拟机&#xff0c;Java二进制字节码的运行环境好处&#xff1a; 一次编写&#xff0c;到处运行自动内存管理&#xff0c;垃圾回收的功能数组下标越界检查&#xff08;会抛异常&#xff0c;不会覆盖到其他代码…...

postgresql|数据库|只读用户的创建和删除(备忘)

CREATE USER read_only WITH PASSWORD 密码 -- 连接到xxx数据库 \c xxx -- 授予对xxx数据库的只读权限 GRANT CONNECT ON DATABASE xxx TO read_only; GRANT USAGE ON SCHEMA public TO read_only; GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_only; GRANT EXECUTE O…...

【HTTP三个基础问题】

面试官您好&#xff01;HTTP是超文本传输协议&#xff0c;是互联网上客户端和服务器之间传输超文本数据&#xff08;比如文字、图片、音频、视频等&#xff09;的核心协议&#xff0c;当前互联网应用最广泛的版本是HTTP1.1&#xff0c;它基于经典的C/S模型&#xff0c;也就是客…...

《C++ 模板》

目录 函数模板 类模板 非类型模板参数 模板特化 函数模板特化 类模板的特化 模板&#xff0c;就像一个模具&#xff0c;里面可以将不同类型的材料做成一个形状&#xff0c;其分为函数模板和类模板。 函数模板 函数模板可以简化函数重载的代码。格式&#xff1a;templa…...

C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...

Golang——9、反射和文件操作

反射和文件操作 1、反射1.1、reflect.TypeOf()获取任意值的类型对象1.2、reflect.ValueOf()1.3、结构体反射 2、文件操作2.1、os.Open()打开文件2.2、方式一&#xff1a;使用Read()读取文件2.3、方式二&#xff1a;bufio读取文件2.4、方式三&#xff1a;os.ReadFile读取2.5、写…...

嵌入式常见 CPU 架构

架构类型架构厂商芯片厂商典型芯片特点与应用场景PICRISC (8/16 位)MicrochipMicrochipPIC16F877A、PIC18F4550简化指令集&#xff0c;单周期执行&#xff1b;低功耗、CIP 独立外设&#xff1b;用于家电、小电机控制、安防面板等嵌入式场景8051CISC (8 位)Intel&#xff08;原始…...

算术操作符与类型转换:从基础到精通

目录 前言&#xff1a;从基础到实践——探索运算符与类型转换的奥秘 算术操作符超级详解 算术操作符&#xff1a;、-、*、/、% 赋值操作符&#xff1a;和复合赋值 单⽬操作符&#xff1a;、--、、- 前言&#xff1a;从基础到实践——探索运算符与类型转换的奥秘 在先前的文…...

PH热榜 | 2025-06-08

1. Thiings 标语&#xff1a;一套超过1900个免费AI生成的3D图标集合 介绍&#xff1a;Thiings是一个不断扩展的免费AI生成3D图标库&#xff0c;目前已有超过1900个图标。你可以按照主题浏览&#xff0c;生成自己的图标&#xff0c;或者下载整个图标集。所有图标都可以在个人或…...