• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  C++ Primer

Standing on Shoulders of Giants
fstream--文本数据迁移

摘要:1 // ifile_ofile_test.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 9 #include <iostream>10 #include <fstream>11 #include <string>12 13 int move_data(const std::string _ifilename, const std::string _ofilename) 阅读全文
posted @ 2012-12-27 17:05 lovemu 阅读(385) 评论(0) 推荐(0)
覆盖与隐藏

摘要:1 class A 2 { 3 public: 4 A(int num); 5 virtual ~A(); 6 int action(int info); 7 int goaction(); 8 virtual int getlastValue(); 9 protected:10 int generateValue();11 private:12 int value;13 int flag;14 int lastValue;15 };16 class B:public A17 {18 ... 阅读全文
posted @ 2012-10-23 12:25 lovemu 阅读(241) 评论(0) 推荐(0)
operator(3)赋值例子

摘要:1 #include "stdafx.h" 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 6 class Test 7 { 8 public: 9 Test():mValue(2),mName("karen")10 {11 }12 Test(string x,int y)13 {14 mName = x;15 mValue = y;16 }17 ~Test()18 {19 }20 int getVal... 阅读全文
posted @ 2012-08-23 14:49 lovemu 阅读(244) 评论(0) 推荐(0)
operator(2)输入输出与比较例子

摘要:1 #include "stdafx.h" 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 6 class Test 7 { 8 public: 9 Test():mValue(2),mName("karen")10 {11 }12 Test(string x,int y)13 {14 mName = x;15 mValue = y;16 }17 ~Test()18 {19 }20 friend ... 阅读全文
posted @ 2012-08-23 11:09 lovemu 阅读(537) 评论(0) 推荐(0)
operator(1)算术与比较例子

摘要:1 #include "stdafx.h" 2 #include <iostream> 3 #include <math.h> 4 using namespace std; 5 class Room 6 { 7 public: 8 Room() 9 {10 }11 ~Room()12 {13 }14 void setHeight(double ht)15 {16 value = ht;17 }18 double getHeight()19 {20 return (value... 阅读全文
posted @ 2012-08-23 09:45 lovemu 阅读(287) 评论(0) 推荐(0)
函数中的static变量

摘要:1、只在进入和退出变量作用域之间维护变量的值,静态变量的一种通常用法是“记住”是否已经为一个函数完成过特定的初始化。第一次调用performTask(),inited值为false;第二次调用performTask()时,inited值为true;因为当程序加载时,就已为其分配内存空间。代码例子如下: 1 #include "stdafx.h" 2 #include <iostream> 3 4 void performTask() 5 { 6 static bool inited = false; 7 if(!inited) 8 { 9 std::cout&l 阅读全文
posted @ 2012-08-20 11:51 lovemu 阅读(2523) 评论(0) 推荐(0)
类模板与类方法模板

摘要:1 // TemplateTest.cpp : 定义控制台应用程序的入口点。 2 3 4 #include "stdafx.h" 5 #include <iostream> 6 /*非模板定义类*/ 7 class NewTest 8 { 9 public: 10 NewTest(int t) 11 { 12 mOut = t; 13 } 14 15 virtual int action(int mIn) 16 { 17 mRes = mIn + mOut; 18 return (mRes... 阅读全文
posted @ 2012-08-17 16:45 lovemu 阅读(1633) 评论(0) 推荐(0)
const方法

摘要:1、先看下一个类Test.h 1 #define PI 3.14159 2 const int NUM = 3;//定义常量 3 class Test 4 { 5 public: 6 Test(); 7 virtual ~Test(); 8 virtual void action(const int input);//保护,防止意外修改 9 int getstate() const;10 const MyClass istate();11 private:12 static int mLay;13 ... 阅读全文
posted @ 2012-08-16 11:39 lovemu 阅读(1382) 评论(0) 推荐(0)
static--静态方法与静态成员

摘要:1、Test.h 1 class Test 2 { 3 public: 4 Test(); 5 virtual ~Test(); 6 virtual void action(); 7 static virtual void go(); 8 private: 9 static int mLay;10 int mOut;11 12 };此处,static 与 virtual不能共用,此时这里去掉virtual关键字。2、Test.h 1 class Test 2 { 3 public: 4 Test(... 阅读全文
posted @ 2012-08-16 10:00 lovemu 阅读(351) 评论(0) 推荐(0)
顺序容器 (2)string类型操作

摘要:1 #include "stdafx.h" 2 #include <string> 3 #include <iostream> 4 using namespace std; 5 6 int _tmain(int argc, _TCHAR* argv[]) 7 { 8 string file_path = "d:/karen/love/you"; 9 int pathsize = file_path.size();//元素个数10 string full_path;11 if(file_path.find_last_of(" 阅读全文
posted @ 2012-04-26 17:07 lovemu 阅读(226) 评论(0) 推荐(0)
顺序容器 (1)string类型操作

摘要:1 #include "stdafx.h" 2 #include <string> 3 #include <iostream> 4 using namespace std; 5 int _tmain(int argc, _TCHAR* argv[]) 6 { 7 string s="352225198807081013.10086.777.505"; 8 int pos = s.find_last_of(".");//string查找操作 9 string s1 = s.substr(pos+1,3);//截取 阅读全文
posted @ 2012-04-24 21:40 lovemu 阅读(248) 评论(0) 推荐(0)
标准IO库

摘要:ifstream由istream派生而来,从文件中读取;ofstream由ostream派生而来,写到文件中去;fstream由iostream派生而来,读写文件;IO 1 #include "stdafx.h" 2 #include <fstream> 3 #include <iostream> 4 #include <string> 5 using namespace std; 6 int _tmain(int argc, _TCHAR* argv[]) 7 { 8 ifstream infile; 9 ofstream outfil 阅读全文
posted @ 2012-04-24 21:13 lovemu 阅读(253) 评论(0) 推荐(0)
map关联容器(1)

摘要:编译环境:VS2008第一个map程序: 1 #include "stdafx.h" 2 #include <string> 3 #include <map> 4 #include <iostream> 5 6 using namespace std; 7 8 int _tmain(int argc, _TCHAR* argv[]) 9 {10 map<string,int> word_count;11 word_count.insert(make_pair("karen",29));12 map<s 阅读全文
posted @ 2012-04-15 23:13 lovemu 阅读(297) 评论(0) 推荐(0)

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3