对string 简单应用
2017-11-26 12:30
302 查看
#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; }
相关文章推荐
- 【Boost】boost::string_algo详解3——finder的简单应用
- HDU4850-Wow! Such String!-hash简单应用
- String.Format(string format, object arg0) 简单应用
- String的简单应用
- java String.indexOf方法在一个字符串中查找另一个字符串的次数的简单应用
- stl string 简单应用
- boost::string_algo详解3——finder的简单应用
- boost::string_algo详解3——finder的简单应用
- Objective-C中NSString与NSMutableString的一些简单应用
- vue-router单页应用简单示例(三)
- Timer、TimerTask的简单应用及如何解决多次调度相同任务。
- 数据结构实验之串一:KMP简单应用
- JavaFX实现简单聊天室应用(服务器端)
- WCF的简单应用
- 一个简单的flex应用
- 粒子群算法针对数学规划问题的简单应用
- Rest API的简单应用
- 2009-03-03读书记录:《网页制作与PHP语言应用》第五章——简单PHP程序应用(下)
- GDataXMLNode解析xml数据的简单应用
- 【转】linux dd 的简单应用