C++
@@@lv
这个作者很懒,什么都没留下…
展开
-
C++中substr函数的用法
C++中substr函数的用法includeincludeusing namespace std;main() { string s(“12345asdf”); string a=s.substr(0,5); //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾 cout<...转载 2018-04-12 11:25:10 · 116 阅读 · 0 评论 -
C++_优化冒泡排序_在for循环中使用bool值
#include <iostream>using namespace std;void h(int a[], int n) { for (bool s = false; s = !s; n--) // 利用bool值判断数组是否有序 for (int i = 1; i < n; i++) if (a[i-1] >...翻译 2019-01-19 22:50:17 · 671 阅读 · 2 评论 -
高精度减法(C++)
题目:处理俩个高精度的减法。(1000位内)输入:俩行,每行一个整数。(可能为负数,负号用“-”表示)输出:一个整数,既两个数相减的结果。#include <iostream>#include <string>using namespace std;string st, str1,str2;int a[1000],b[1000],c[1000];...原创 2018-12-03 16:24:22 · 3807 阅读 · 1 评论 -
大数阶乘求和
#include <iostream>#include <vector>using namespace std;bool flag = true;vector<int> sum;// 大数阶乘vector<int> BigFactorial(int m){ int a[50000]={0,1}; int i,j,carry...原创 2018-10-12 17:42:48 · 327 阅读 · 0 评论 -
C++中empty()函数的使用
C++中empty()作为判断容器是否为空的函数;string s;if (s.empty()) { cout << “字符串为空”;}else{ cout << "字符串不为空";}原创 2018-04-13 21:18:36 · 58101 阅读 · 1 评论 -
MFC-1-C++基础
面向对象程序设计OOP(面向对象编程)封装了大量的Windows API函数翻译 2018-07-05 16:22:14 · 127 阅读 · 0 评论 -
C++_当前时间 | 计时器
//将当前时间折算为秒级,再通过函数转换成时分秒#include<iostream> #include<iomanip>#include<ctime> using namespace std;int main(){ time_t now_time; now_time = time(NULL); // 获取当前时间 cout <...原创 2018-07-19 21:32:36 · 336 阅读 · 0 评论 -
C++_char输出乱码
#include <iostream>using namespace std;int main(){ int ia; char ca[] = { '0','1','2','3','\0' }; int* iptr = &ia; const char* cptr = &ca[0]; // int类型占4字节。指针加1地址加4. cout &...原创 2018-07-22 10:07:36 · 10296 阅读 · 0 评论 -
C++_函数返回指针
C++ 允许从函数返回指针。为了做到这点,必须声明一个返回指针的函数,如下所示:int * myFunction(){ static int c[10]; ... return c;}C++ 不支持在函数外返回局部变量的地址,除非定义局部变量为 static 变量。...原创 2018-07-22 10:40:59 · 1678 阅读 · 0 评论 -
C++_引用与指针的区别
引用很容易与指针混淆,他们之间由三个主要的不同:不存在空引用。引用必须连接到一块合法的内存。 一旦引用被初始化为一个对象,就不能被指向另一个对象。指针可以在任何时候指向另一个对象。 引用必须在创建时被初始化。指针可以在任何时间被初始化。引用作为返回值,必须遵守以下规则:(1)不能返回局部变量的引用。主要原因是局部变量会在函数返回后被销毁,因此被返回的引用就成为了"无所指"的引用,程序...原创 2018-07-22 10:55:03 · 402 阅读 · 0 评论 -
C++_MyList
main.cpp中#include <iostream>#include <string>#include "List.h"#include "node.h"using namespace std;void main(){ List<char *> cmdlist; cmdlist.add("china"); cmdlist.sho..原创 2018-09-01 19:21:26 · 273 阅读 · 0 评论 -
C++分割字符串
void SplitString(const string& s, vector<string>& v, const string& c){ string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (string::npos != pos2) { v.push_back(s...转载 2019-05-05 16:47:51 · 175 阅读 · 0 评论