⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.h

📁 这是一个银行系统的管理软件
💻 H
字号:
/**********************************************************************************
*                                                                                 *
*  Henry's Common Toolkit for C++                                                 *
*  Copyright (c) 2004 by Henry. All rights reserved.                              *
*                                                                                 *
*  Permission to use, copy, modify, and distribute this software for any purpose  *
*  is hereby granted without fee, provided that this copyright and permissions    *
*  notice appear in all copies and derivatives, and that no charge may be made    *
*  for the software and its documentation except to cover cost of distribution.   *
*                                                                                 *
*  This software is provided "as is" without express or implied warranty.         *
*                                                                                 *
**********************************************************************************/

/*
*  Description:
*
*    All common functions here.
*
*  Notes:
*
*    This code has been written to conform to standard C++ and STL. It has been
*    compiled successfully using Visual C++ 7.0.
*/

#ifndef GUARD_common_h
#define GUARD_common_h

#define ALIGN_LEFT		0
#define ALIGN_CENTER	1
#define ALIGN_RIGHT		2

#include <string>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <vector>

using namespace std;

static string getNow()
{
	string dateTime = "20";
	char dbuffer [9];
    char tbuffer [9];
	_strdate( dbuffer );
	dateTime += dbuffer;
	dateTime += " ";
	_strtime( tbuffer );
	dateTime += tbuffer;
	return dateTime;
}

static double string2double(string value)
{
	return atof(value.c_str());
}


static string double2string(double value)
{
	string res = "";
	char buffer[20];
	gcvt(value, 12, buffer);
	res += buffer;
	return res;
}


static size_t string2long(string value)
{
	double temp = string2double(value);
	return (size_t)temp;
}


static string long2string(size_t value)
{
	string temp = double2string((double)value);
	return temp.substr(0, temp.size() - 1);
}


static void outputVector(vector<string> vec)
{
	cout << endl;
	for(vector<string>::size_type i = 0; i <= vec.size() - 1; i++)
	{
		cout << vec[i] << endl;
	}
}

static string format(string str, size_t size, size_t align, size_t spaceCount)
{
	size_t leftSpace, rightSpace;
	switch(align)
	{
	case ALIGN_LEFT:
		leftSpace = spaceCount;
		rightSpace = size - str.size() - spaceCount;
		break;
	case ALIGN_CENTER:
		leftSpace = (size - str.size()) / 2;
		rightSpace = size - leftSpace - str.size();
		break;
	case ALIGN_RIGHT:
    leftSpace = size - str.size() - spaceCount;
		rightSpace = spaceCount;
	}
	return string(leftSpace, ' ') + str + string(rightSpace, ' ');
}

static string format(string str, size_t size, size_t align)
{
	return format(str, size, align, 0);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -