C++ string类型
来源:互联网 发布:淘宝正常一天能出几单 编辑:程序博客网 时间:2024/06/02 07:02
没办法,测试需要,转c++,请指教。
// ConsoleApplication2.cpp: 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <string>using namespace std;int main(){ //字符串初始化方式 string s1("Hello world"); cout << "s1="<<s1 << endl; cout << "s1.length=" << s1.length() << endl; //string地址初始化方式 string alter("hello world2"); string s2(alter); cout << "s2=" << s2 << endl; cout << "s2.length=" << s2.length() << endl; //子字符串初始化方式 string s3(alter, 0, 5);//不取第6个字符 cout << "s3=" << s3 << endl; cout << "s3.length=" << s3.length() << endl; //由固定长度指针c字符数组转化 char oper[]={'H','e','l','l','o'}; //char *opera = oper;//结果相同 string s4(oper); cout << "s4=" << s4 << endl; cout << "s4.length=" << s4.length() << endl; //固定长度指针,指定长度 string s5(oper, 5); cout << "s5=" << s5 << endl; cout << "s5.length=" << s5.length() << endl; //使用特殊标签 string s6(s1.begin(), s1.begin() + 5); cout << "s6=" << s6 << endl; cout << "s6.length=" << s6.length() << endl; string pses6(s1.end()-7, s1.end()); cout << "pses6=" << pses6 << endl; cout << "pses6.length=" << pses6.length() << endl; //从C字符数组转化为字符串这里太不灵活,我要读取这个字符数组,必须知道它的长度。 //用c++的string类型可以方便操作,在公司面试的OS中。 s5 = oper; cout << "s5=" << s5 << endl; cout << "s5.length=" << s5.length() << endl; //很多时候需要重新赋值。所以应该寻求以一种更好的方法,待续 return 0;}
阅读全文
0 0
- C++string类型详解
- C++ STL string类型
- c++string类型管理
- c#string类型探讨
- char类型和string类型(C++,C#)
- char类型和string类型(C++,C#)
- 关于C#string的类型
- C string类型的用法
- C风格字符串&string类型
- c++string 字符串类型用法
- c++string类型的应用
- c语言string类型转为double类型
- 【C++】string类型与数字类型互换
- C/C++ string类型转换int类型
- c/c++string 转化其他类型
- C++string类型转换为C数组
- 标准C程式库--问题例--类型 String
- C#—特殊引用类型string
- 进程的三种基本状态及其转换
- git 学习
- Collection中List,Set的排序
- js中json对象key值首字母大写化
- TCP为什么需要3次握手与4次挥手
- C++ string类型
- Pythonic QuickSort
- 第三周项目一C/C++顺序表的基本运算
- 【转】linux grep命令
- UNIX 设置 JAVA 环境变量
- JDBC技术简介
- c-learning-note(2017-9-21)
- SCUT Training 20170920 Problem C
- Day02 继承 匿名对象 Final Abstract