basicstringtool.h
来自「在年级成绩管理系统中」· C头文件 代码 · 共 77 行
H
77 行
#include <strstream>
namespace BasicStringTool
{
class NumberToString
{
public:static std::string FromInt(int number)
{
char ch[12];
std::strstream strs(ch,12);
strs<<number;
strs<<std::ends;
std::string str(ch);
return str;
}
public:static std::string FromFloat(float number)
{
char ch[12];
std::strstream strs(ch,12);
strs<<number;
strs<<std::ends;
std::string str(ch);
return str;
}
};
class StringToInt
{
public:static int Get(const std::string& str)
{
int number=0;
int len=str.length();
int temp;
bool eff=false;
for(int i=0;i<len;i++)
{
temp=str[i]-'0';
if(temp<0||temp>9)
{
if(eff==false)
continue;
else
break;
}
number=10*number+temp;
eff=true;
}
return number;
}
};
class WordFromString
{
public: static std::string Get(const std::string& strToGet)// const
{
bool eff=false;
int count=0;
char ch;
int len=strToGet.length();
std::string word;
while(count < len)
{
ch=strToGet[count++];
if((ch<'a'|| ch>'z') && (ch<'A'|| ch>'Z')&&(ch<'0'|| ch>'9'))
{
if(eff == false)
continue;
else
break;
}
word += ch;
eff = true;
}
return word;
}
};
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?