c++ cctype sort cctype string stoi stod

14 篇文章 0 订阅

cctype
~isalpha 字母(包括大写、小写)
~islower(小写字母)
~isupper(大写字母)
~isalnum(字母大写小写+数字)
~isblank(space和\t)
~isspace(space、\t、\r、\n)

  • tolower (->小写

  • toupper(->大写
    以下是简单的cctype以及sort

#include<vector >
#include<algorithm>
#include<iostream>
#include<cctype>
#include<string> 
using namespace std;
bool cmp(int a,int b){
	return a>b;//从大到小排序 ,似乎不允许 =
}
int main(){
	vector<int> w(10);
	for(int i=0;i<10;i++){
		w.push_back(i+1); 
	}
	cout<<endl; 
	sort(w.begin() ,w.end() ,cmp);
	for(int i=0;i<10;i++){
		cout<<w[i]<<" "; 
	}
	if(isalnum('K')) printf("Y");//cctype 的 应用la~ 
	else printf("N");
	puts(" ");
	char m='a';
	printf("%c",toupper(m));//转为大写
	
	
} 

to_string int,float之类 ->>string

#include<vector >
#include<algorithm>
#include<iostream>
#include<cctype>
#include<string> 
using namespace std;

int main(){

	string ok,ko;
	ok=to_string(123);//turn to字符 
	ko=to_string(45); 
	cout<<ok+ko<<endl;//两个字符串连接输出!
	printf("%s",(ok+ko).c_str()); //printf 对应操作! 
	
	
	
} 

stoi stod ;

#include<vector >
#include<algorithm>
#include<iostream>
#include<cctype>
#include<string> 
using namespace std;

int main(){

	string ok="123",ko="11.11";
	int a;
	double b;
	a=stoi(ok);//string turn to int 
	b=stod(ko);//string turn to double 
	cout<<a<<" ";
	cout<<b<<" ";
	
	
	
} 

stold;
stoll;
stof;
stoul;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值