toolfun.cpp

来自「标准C++编写的小小CRM软件,无任何平台依赖.采用标准XML作为数据库.只需重」· C++ 代码 · 共 64 行

CPP
64
字号
#include "ToolFun.h"

bool strCompare(char *ch1,char *ch2)
/* this strCompare function is little diffrent to normal string		* 
 * compare. If all charactor of two string are same, then It		*
 * return true, else return false.									*/
{
	while(*ch1!='\0' || *ch2!='\0'){
		if( *ch1!=*ch2 )
		{	return false;	}
		ch1++;
		ch2++;
	}
	if( *ch1=='\0' && *ch2=='\0' )
	{	return true;	}
	else
	{	return false;	}
}

int  toInt( char* str )
/* convert digital string to integer. If success return a integer,	*
 * else return 0.													*/
{
	int i;

	istrstream intStr( str,sizeof(str) );
	if( intStr>>i )	{	return i;	}
	else			{	return 0;	}
}

int  toInt( const string& str)
/* convert digital string to integer. If success return a integer,	*
 * else return 0.													*/
{
	int i;

	istrstream intStr( str.data(),str.length() );
	if( intStr>>i )	{	return i;	}
	else			{	return 0;	}
}

float  toFloat( char* str)
/* convert digital string to float. If success return a float,		*
 * else return 0.													*/
{
	float f;

	istrstream intStr( str,sizeof(str) );
	if( intStr>>f )	{	return f;	}
	else			{	return 0;	}
}
float  toFloat( const string& str)
/* convert digital string to float. If success return a float,		*
 * else return 0.													*/
{
	float f;

	istrstream intStr( str.data(),str.length() );
	if( intStr>>f )	{	return f;	}
	else			{	return 0;	}
}


⌨️ 快捷键说明

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