各种乱七八糟常用函数的简单用法(不定期更新)

【全排列】

头文件:
#include <algorithm>
用法:

do
    {
        
    }while(next_permutation(a+i,a+j));//将a+i到a+j的子串进行全排列
例:
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char a[6]="abcde";
    do
    {
        cout<<a<<endl;
    }while(next_permutation(a+1,a+4));
    return 0;
}


【字符转换成数字】

1.atoll

头文件:
#include <cstdlib>
用法:
long long a=atoll(const b)//将字符串b转换成长长整型的数a(b为字符串头指针)
例:
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    char a[20]="123456789123456789";
    long long  b;
    b=atoll(a);
    cout<<b<<endl;
    return 0;
}


其他类似函数:
atof(将字符串转换成浮点型数)
atoi(将字符串转换成整型数)
atol(将字符串转换成长整型数)
strtod(将字符串转换成浮点数)
strtol(将字符串转换成长整型数)
strtoul(将字符串转换成无符号长整型数)
toascii(将整型数转换成合法的ASCII 码字符)
toupper(将小写字母转换成大写字母)
tolower(将大写字母转换成小写字母)

【#define #ifdef #endif 的简单用法】

#include <iostream>
#define debug
using namespace std;
void DEBUG()
{
    #ifdef debug
    cout<<"++++++++++"<<endl;
    #endif
}
int main()
{
    cout<<"----------"<<endl;
    DEBUG();
    return 0;
}

#include <iostream>
//#define debug   //加了注释
using namespace std;
void DEBUG()
{
    #ifdef debug
    cout<<"++++++++++"<<endl;
    #endif
}
int main()
{
    cout<<"----------"<<endl;
    DEBUG();
    return 0;
}



【字符逆置】

头文件:
#include <cstring>
例:
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    char str[10];
    cin>>str;
    strrev(str);
    cout<<str<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值