自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 算括号表达式的实现

#include  #include #include using namespace std;double Result(const string &expression);int main(){cout string s;getline(cin, s);cout system("pause");return 0;}doub

2017-03-23 11:36:01 246

原创 接受一个日期的构造函数

C++ Primer 5th 9.51#include  #include #include #include using namespace std;struct Date{unsigned year;unsigned month;unsigned day;string theyear;string themonth;string th

2017-03-22 15:20:53 287

原创 查找字符串中的每个数字与字母并输出

C++ Primer 5th 9.47题#include  #include #include using namespace std;void Number(const string &s);void Zimu(const string &s);int main(){string s = "ab2c3d7R4E6";Number(s);Zimu

2017-03-21 15:14:23 1366

原创 字符串的替换

C++ Primper 5th 9.43,9.44题在字符串中找一个字符串。若找到就替换为另一个字符串方法一:使用erase函数和insert函数和迭代器#include  #include using namespace std;void Replace(string &s, const string &oldVal, string &newVal);

2017-03-21 10:46:57 339

原创 例题:在链表中查找一个字符串,并插入另一个字符串

题目为C++ primer 9.28#include  #include #include using namespace std;void Insert(forward_list &lst, const string &a, const string &b);int main(){forward_list lst{ "nayeon","tzuyu","momo

2017-03-17 11:40:44 1417

原创 例题:C++中删除链表中的奇数元素

C++中表示链表的容器是forward_list。首先给链表赋一个初始值,用列表初始化的方法:forward_list lst{1,2,3,4,5,6,7};删除链表中元素的语句是erase_after。如lst.erase_after(iter),iter是一个迭代器,和erase语句不同的是,erase删除的是这个迭代器所指元素,而erase_after删除的是迭代器所指后面的那个元素

2017-03-17 09:30:59 3204

原创 C++读文件

C++读文件时犯了三个错误:一、没有加头文件。文件输入输出需要的头文件是fstream。二、没有把需要读取的文件放在同目录下。同目录下的程序的后缀名应该是vcxproj。三、读取文件中的字符应该用getline函数,直接用istream读取会多一个字符串,不知道为什么。

2017-03-10 17:39:57 598

原创 this指针在类的成员函数中的传递

成员函数形参列表后有无const表明this指针是指向常量还是非常量this指针会传向子函数,也就是说,如果该函数是有const,那么子函数也必须有const,如:const Screen& display() const{do_display();return *this;}void do_display() const{cout }

2017-03-04 18:07:42 648

原创 C++中构造函数中使用函数进行初始化

返回局部变量不能使用引用,因为局部变量在语句块结束后就会被销毁,找不到。这时候要使用拷贝。比如:Person read(istream &it){Person thePerson;it >> thePerson.name >> thePerson.address;return thePerson;}返回的是一个对象,构造函数想在初始化的时候变成这个对象,那么就需

2017-03-04 11:04:34 518

原创 头文件怎么写

首先创建一个头文件。格式为xxx.h。头文件的头文件保护符格式为:开头:#ifndef XXX_H#define XXX_H注意全变成大写结尾:#endif在源程序中引用头文件:#include "xxx.h"

2017-03-03 23:11:10 956

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除