对string 简单应用
来源:互联网 发布:unity3d弯折 编辑:程序博客网 时间:2024/06/07 04:47
#include<iostream>#include<iomanip>#include<string>using namespace std;int main(int argc, char** argv) { string str = "高德纳 美国 计算机科学家 计算机程序设计艺术"; string str_temp = " "; str_temp.assign(str);// 字符串复制 string result[4] = { " "," " ," "," " }; int position = 0; for (int i = 0; i < 3; i++) { position = str_temp.find(" ");//第一次出现的位置 result[i] = str_temp.substr(0, position);// 取出字符串从0 开始 position 个字符 str_temp = str_temp.substr(position + 1, str_temp.length() - position); // 删除上述字符 } result[3] = str_temp; cout << "姓名: " << setw(8) << result[0] << endl; cout << "国籍: " << setw(6) << result[1] << endl; cout << "职业:" << setw(14) << result[2] << endl; cout << "代表作 : " << setw(18) << result[3] << endl; str_temp.swap(result[0]); // 将本字符串与result 进行交换 for (int j = 1; j < 4; j++) { str_temp += " "; str_temp.append(result[j]); // 还原操作 将result 追加到本字符串末尾 } int equal = str.compare(str_temp); // 将两个字符串进行比较 相同 结果为零 if (equal == 0) { cout << "Success Matching!" << endl; } else cout << "Unsuccessful Matching!" << endl; return 0;}
阅读全文
0 0
- 对string 简单应用
- stl string 简单应用
- c++ string 简单应用一
- string.format的简单应用
- C#中String类的简单应用
- C++之string vector bitset简单应用
- HDU4850-Wow! Such String!-hash简单应用
- String.Format(string format, object arg0) 简单应用
- 我对简单权限应用的研究
- 初学者对数据库应用的简单提取
- jQuery 对复选框的简单应用
- C++对fabs的简单应用
- c++对合数的简单应用
- UVA10916取对的简单应用
- 对WindowListener接口的简单应用
- 简单的谈一下对String 的认识
- Redis简单入门二——对String类型操作
- 对String在多线程中的一些简单认识
- 让专业变成兴趣之Linux系统运维
- c++primer第五版 练习5.20
- 子空间与正交投影
- 理解Docker跨多主机容器网络
- MD5算法常见坑
- 对string 简单应用
- iOS 后台下载及管理库
- keras上手系列之:序列到序列预测问题
- 实现全选效果
- html&tomcat
- 图像拼接和图像融合技术
- input file图片预览
- 树莓派装上samba, 方便文件传输
- linux下mysql环境搭建