
C/C++
赤云
这个作者很懒,什么都没留下…
展开
-
1.c++简单的成员变量和成员函数
#include<iostream>#include<string.h>using namespace std;class student{private: char name[20]; int a;public: void setName(int); int getName();};student stu;int main(){ stu.se...原创 2018-04-24 16:24:31 · 196 阅读 · 0 评论 -
6. "undefined reference to" 问题汇总及解决方法 ------非常非常好的一篇文章
转载地址: https://segmentfault.com/a/1190000006049907?utm_source=tuicool&utm_medium=referral在实际编译代码的过程中,我们经常会遇到"undefined reference to"的问题,简单的可以轻易地解决,但有些却隐藏得很深,需要花费大量的时间去排查。工作中遇到了各色各样类似的问题,按照以下几种可能出现的...转载 2018-06-02 08:43:17 · 6899 阅读 · 0 评论 -
8.C++中的拼接字符串
用sprintf()函数将一个变量从int类型转换到字符串类型。为了正确地完成这个任务,你必须确保证目标缓冲区有足够大空间以容纳转换完的字符串。此外,还必须使用正确的格式化符。如果使用了不正确的格式化符,会导致非预知的后果。下面是一个例子:int n=10000;chars[10];sprintf(s,”%d”,n);// s中的内容为“10000”到目前为止看起来还不错。但是,对上面代码的一个微...原创 2018-06-22 11:51:17 · 1099 阅读 · 0 评论 -
8.C++写入文件
头文件:#include<fstream> /*打开配置文件*/ ofstream out("input.txt"); if(!out.is_open()){ #if DEBUG cout<<"打开配置文件失败(写入):"<<endl; #endif return -2; } /*...原创 2018-06-22 10:19:46 · 163 阅读 · 0 评论 -
7.C++读取文件的数据
头文件:#include <fstream>(1) #include <fstream>#include <stdlib.h...原创 2018-06-22 10:09:07 · 271 阅读 · 0 评论 -
6.结构体介绍
#include <stdio.h> #include <string.h> struct Student { char name[20]; //学生姓名 unsigned int num; //学号 int isMale; //性别 }s1; int main(v...原创 2018-05-17 17:25:52 · 274 阅读 · 0 评论 -
5.C指针操作——全部替换字符串里某个字符或者某个子串
#include<string.h>#include<stdio.h>#include<stdlib.h>//把source字符串里所有s1字符全部替换成字符s2void replace_char(char *result, char *source, char s1, char s2){ int i = 0; char *q = NULL; ...转载 2018-05-04 09:03:12 · 832 阅读 · 0 评论 -
4.c++中的string类型
在C++中提供了一个型的内建数据类型string,该数据类型可以替代C语言中char数组。需要使用string数据类型时则需要在程序中包含头文件string。1.string类型的简单赋值#include<iostream>#include<string>using namespace std;int main(){ string s1;//默认为空 strin...原创 2018-04-26 11:44:42 · 221 阅读 · 0 评论 -
3.C++函数声明后加const
#include<iostream>using namespace std;class complex{public: complex(); void display() const; void test();private: double real; double imag;};int main(){ complex c; c.display(); ...原创 2018-04-26 10:17:04 · 212 阅读 · 0 评论 -
2.c++参数初始化列表
构造函数初始化列表以一个冒号开始,接着是以逗号分隔的数据成员列表,每个数据成员后面跟一个放在括号中的初始化式。例如:#include<iostream>using namespace std;struct test1{ test1():a(5),b(10) { //a = 5; //b = 10; cout<<"a="&...原创 2018-04-25 10:29:24 · 920 阅读 · 0 评论 -
9.C++中的base64编解码实现
#include <string>#include <iostream>#include<stdio.h>using namespace std;std::string base64_encode(unsigned char const* , unsigned int len);std::string base64_decode(std::strin...原创 2018-09-07 15:04:07 · 1047 阅读 · 0 评论