经验:异常安全函数即使发生异常也不会泄漏资源或允许任何数据结构败坏。这样的函数区分为三种
可能的保证:
基本型-->发生异常,程序处于某个合法状态
强烈型-->发生异常,程序处于原先状态
不抛异常型-->承诺绝不抛出殿堂
示例:
class PrettyMenu{
public:
//...
void changeBackground(std::istream &imgSrc); //改变背景图像
//...
private:
Mutex mutex; //互斥器
Image *bgI...
分类:
编程语言 时间:
2014-07-12 21:35:16
阅读次数:
298
将输入的一行读到string中不需要像用数组那样,考虑给多少大小的空间,这可以使得做acm题更加方便。
c++98有两个函数可以读一行到string中,如下:
istream& getline (istream& is, string& str, char delim);
istream& getline (istream& is, string& str);
例子:
#in...
分类:
编程语言 时间:
2014-07-04 07:52:26
阅读次数:
285
文件读写、游标
seekg
函数原型:
istream &seekg( off_type offset, ios::seekdir origin );
istream &seekg( pos_type position );
函数seekg()用于输入流,并且它将重新设置"get"指针到当前流的从origin偏移offset个字节的位置上,或是置"get"指针在posit...
分类:
其他好文 时间:
2014-07-03 15:57:31
阅读次数:
225
(一)先看下面这些代码:
class PrettyMenu {
public:
void changeBackground(istream& imgSrc);
private:
Mutex mutex; //由于这个class希望用于多线程环境,所以它有这个互斥器作为并发控制之用
Image* bgImage; //目前的背景图像
int imageChan...
分类:
编程语言 时间:
2014-06-25 08:35:48
阅读次数:
339
在C++编程中实现数据的输入/输出可以用cin>>ch/cout
但是使用cin>>ch或cout
为了解决对于特殊数据的输入和输出在C++中可以使用运算符重载的方式实现,可以通过重载>>和
1重载>>
重载函数的形式:
friend istream& operator >>(istream& input, Complex& c);
第一个参数: istrea...
分类:
其他好文 时间:
2014-06-18 11:50:22
阅读次数:
278
Android中加载位图的关键的代码: AssetManager assets
=context.getAssets(); //用一个AssetManager 对象来从应用程序包的已编译资源中为工程加载资产 InputStream
istream=assets.open("/*位图的名字*/");B...
分类:
移动开发 时间:
2014-05-19 20:53:10
阅读次数:
271
#include
//using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
friend ostream& operator
friend istream& operator>>(istream&,Matri...
分类:
其他好文 时间:
2014-05-12 22:39:15
阅读次数:
387
NewMail 对象(CDONTS 库)发送邮件
速查
声明的类型库: CDONTS.DLL
首次启用: CDO for NTS Library 版本 1.2
父对象: (无)
子对象: (无)
默认属性: Value
属性
名 首次启用版本 类型 访问
Bcc 1.2 字符串 只写
Body 1.2 IStream 对象或字符串 只写
BodyForma...
分类:
其他好文 时间:
2014-05-10 03:43:53
阅读次数:
312
Socket是一个用于机器之间通信的类。Socket客户端:(1)Socket s = new
Socket(ip,port);打开一个套接字,发送请求(2)InputStream istream =
s.getInputStream();接收数据(3)OutputStream ostream = ...
分类:
其他好文 时间:
2014-05-09 08:43:13
阅读次数:
215
STL定义了供输入及输出的iostream iterator类,称为
istream_iterator和ostream_iterator,分别支持单一型别的元素的读取和写入。使用方法:1.包含头文件: #include using
namespace std; 2.像使用其他iterator一...
分类:
其他好文 时间:
2014-05-07 20:52:40
阅读次数:
629