
C/C++
学习、使用记录
自由的指针*
这个作者很懒,什么都没留下…
展开
-
memcpy&strcpy溢出现象记录
内存复制在地址极限使用情况下有可能溢出的问题原创 2023-03-24 00:09:02 · 766 阅读 · 0 评论 -
c++ 2*N数组分配为两个数组,使得差最小
源代码结果原创 2022-02-15 12:08:39 · 739 阅读 · 0 评论 -
C++ STL 倒序输出单词
单词按照空格倒序输出原创 2022-01-26 08:35:30 · 589 阅读 · 0 评论 -
C++ STL系列---------从输入字符中获取某个字符出现的次数,不区分大小写
代码#include <iostream> #include <string>#include <algorithm>#include <vector>using namespace std;int main(){ string input; char cRetrive; int i = 0; getline(cin,input); // getline(cin,cRetrive); c原创 2022-01-21 21:47:15 · 572 阅读 · 0 评论 -
C++ STL学习
List item计算字符串最后一个单词的长度,单词以空格隔开。例如:输入Hello World,输出5。代码#include <iostream>#include <algorithm>#include <vector>#include <string>using namespace std;int main(){ string input; cout<<"please input:"<<e.原创 2022-01-21 17:32:56 · 284 阅读 · 0 评论 -
QT 多线程 信号及槽的入门使用
创建QT 线程MyThread.h#ifndef MYTHREAD_H#define MYTHREAD_H#include<QThread>class MyThread : public QThread{public: MyThread(); void run();};#endif // MYTHREAD_HMyThread.cpp#include "mythread.h"#include<QDebug>MyThread:原创 2021-09-03 00:36:46 · 209 阅读 · 0 评论 -
c语言 struct 占用内存理解
结论当偏移地址不能整除类型时,成员变量偏移地址后移,直到能整除;整个结构体的大小为对齐参数的整数倍;对齐参数为除去char的所有成员类型大小的最大公约数,成员全是char则为1。对齐的目的是方便计算机编译器取值,加快数据处理速度。举例1数组可以看成n个单独元素。23 变量顺序不一样,结构体占用内存也不一致对比...原创 2021-04-02 10:44:36 · 909 阅读 · 3 评论 -
QT开发的应用——简易计算器_v1.1版本
前言在v1.0的基础上进行改善,简化代码,扩展多位运算。UI设计代码mainwindow.h代码:#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidge原创 2021-01-27 18:05:44 · 200 阅读 · 1 评论 -
QT开发的应用——简易计算器_v1.0版本
前言主题程序参考了以下博客,再他的基础上增加了小数运算结果显示和清除操作。https://www.jianshu.com/p/426f69a07957UI设计创建工程后进入ui文件,放置PushButton和LineEdit,效果如下:选中控件,鼠标右键 选择‘转到槽’,生成对应的控件监听程序。程序编写mainwindow.h程序#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>names原创 2021-01-27 16:36:56 · 169 阅读 · 0 评论 -
牛顿迭代法求平方根、立方根(计算一个数字的平方根、立方根,不使用库函数)
求Y的平方根公式C++代码#include <iostream>#include <cmath>using namespace std;double getSquareBoot(double Y,double precision){ if (Y == 0) return (double)0; double an1 = 0; double an = 1;...原创 2020-03-31 18:34:55 · 1359 阅读 · 0 评论 -
C++ 计算字符串最后一个单词的长度,单词以空格隔开
#include <iostream>#include <cstring>using namespace std;int main(){ char input[5000] = {'0'}; int i = 0; cin.getline(input,5000);//输入整行 i= strlen(input); if(strchr(in...原创 2020-03-27 15:38:55 · 402 阅读 · 0 评论 -
写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写
#include <iostream>#include <cstring>using namespace std;int main(){ char inputs[5000] = {'0'}; char inputc; int i = 0,j=0; cin.getline(inputs,5000); cin>>inputc...原创 2020-03-27 15:53:55 · 1227 阅读 · 1 评论 -
C++ 写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。
#include <iostream>#include <cmath>using namespace std;int main(){ float input; float num; int nnum; cin>>input; nnum = (int)input;//取整 num = input-nnum;//取小数部分...原创 2020-03-29 15:30:16 · 786 阅读 · 0 评论 -
C++ 输入一个int型的正整数,计算出该int型数据在内存中存储时1的个数
#include <iostream>using namespace std;int main(){ int input, i = 0; cin >> input; while (input > 0) { if (input % 2 !=0) { i++; } input = input / 2; } cout <&l...原创 2020-04-08 23:15:17 · 715 阅读 · 0 评论 -
C++求输入A和B的最小公倍数
#include <iostream>using namespace std;int getMaxCommonDivisor(int a, int b){ int t; while (1) { if (a < b) { t = a; a = b; b = t; } if (b == 0) { return a; br...原创 2020-03-31 15:58:24 · 848 阅读 · 0 评论