33-C++中的字符串类
来源:互联网 发布:凌哥刷枪软件 编辑:程序博客网 时间:2024/05/21 01:47
1、
2、
#include <iostream>#include <string>using namespace std;void string_sort(string a[], int len){ for(int i=0; i<len; i++) { for(int j=i; j<len; j++) { if( a[i] > a[j] ) { swap(a[i], a[j]); } } }}string string_add(string a[], int len){ string ret = ""; for(int i=0; i<len; i++) { ret += a[i] + "; "; } return ret;}int main(){ string sa[7] = { "Hello World", "D.T.Software", "C#", "Java", "C++", "Python", "TypeScript" }; string_sort(sa, 7); for(int i=0; i<7; i++) { cout << sa[i] << endl; } cout << endl; cout << string_add(sa, 7) << endl; return 0;}
3、
4、
5、
string to int to double and int double to string
stringsteam
#include <iostream>#include <sstream>#include <string>using namespace std;#define TO_NUMBER(s, n) (istringstream(s) >> n)#define TO_STRING(n) (((ostringstream&)(ostringstream() << n)).str())int main(){ double n = 0; if( TO_NUMBER("234.567", n) ) { cout << n << endl; } string s = TO_STRING(12345); cout << s << endl; return 0;}
6、
#include <iostream>#include <string>using namespace std;string operator >> (const string& s, unsigned int n){ string ret = ""; unsigned int pos = 0; n = n % s.length(); pos = s.length() - n; ret = s.substr(pos); ret += s.substr(0, pos); return ret;}int main(){ string s = "abcdefg"; string r = (s >> 3); cout << r << endl; return 0;}
7、
阅读全文
0 0
- c中的字符串处理
- C/C++中的字符串
- c中的“字符串”
- C/C++中的字符串
- objective C中的字符串
- C语言中的字符串
- c中的字符串函数
- c语言中的字符串
- C语言中的字符串
- C语言中的字符串
- c语言中的字符串
- C语言中的字符串
- C语言中的字符串
- c语言中的字符串
- c中的字符串
- C语言中的字符串
- C语言中的 字符串
- C语言中的字符串
- K12领域最高融资额落定 VIPKID推出少儿中文平台
- 英语在线教育机构争战AI风口,为何雷声大雨点小?
- HDU 1593 find a way to escape(角速度)
- 阿里加码农村市场 全集团资源运作村淘业务
- linux debian 安装git
- 33-C++中的字符串类
- 1亿元扶持音乐人,繁星网打响“大力发展网络文艺”第一枪
- 均衡首选 ZUK Z1评测
- 《极限挑战》收官在即,OPPO延续挑战活力
- 超时调用和间歇调用
- 在智能时代,你还在用传统机吗?
- iOS.11后的 iOS LaunchImage
- Android HIDL 官方文档(五)—— 快速消息队列(Fast Message Queue ,FMQ)
- JavaScript基础 函数的arguments