![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++ string
文章平均质量分 66
小忒
学习不是应付生活,应付答案。是一种追求,一个理想。
展开
-
String insert() 插入方法
文件头格式#include "stdafx.h"#include #include int main( ){ using namespace std;}-----------------------------------------------------------------basic_string& insert( size_ty转载 2013-02-23 11:00:12 · 48258 阅读 · 0 评论 -
对C++的atoi(),substr(),c_str()函数的理解
刚开始接触C++,很多不懂的地方,翻看老大给的代码其中 year = atoi(dateStr.substr(0, 4).c_str());云里雾里。year = atoi(dateStr.substr(0, 4).c_str());里面包含三个函数,分别是atoi(),substr(),c_str().百度:atoi()函数原型为: int atoi(char *str),用途原创 2012-08-22 14:40:55 · 13408 阅读 · 0 评论 -
C++中delete, new以及new [], delete[]操作符内幕
人们有时好像喜欢故意使C++语言的术语难以理解。比如说new操作符(new operator)和operator new的区别。 当你写这样的代码:string *ps = new string("Memory Management"); 你使用的new是new操作符。这个操作符就象sizeof一样是语言内置的,你不能改变它的含义,它的功能总是一样的。它要完成的功能分转载 2012-08-24 16:34:05 · 538 阅读 · 0 评论 -
vector string的应用
把字符串rusher;lewjan;bill;stan;yx拆成名字,存在vectorstring>里面 例1:#include #include string>#include vector>using namespace std;int main(){ string stmp; stmp="rusher;lewjan;bill转载 2012-08-14 15:23:32 · 1275 阅读 · 0 评论 -
C++ 字符数组函数与string函数
字符串可以用字符数组与字符串变量两种方式来存储,效果类似。一、用字符数组来存储字符串: char st1[100],st2[100] ; //字符数组说明cin>>st1>>st2;long a,b;输入:hello, world则st1={‘h’,’e’,’l’,’l’,’o’,’,’,’\0’}st2={‘w’,’o’,’r’,’l’,’d’,’\0}字符’\0转载 2012-08-24 16:35:49 · 763 阅读 · 0 评论 -
C++中string erase函数的使用
文章出自:http://www.cnblogs.com/liyazhou/archive/2010/02/07/1665421.htmlerase函数的原型如下:(1)string& erase ( size_t pos = 0, size_t n = npos );(2)iterator erase ( iterator position );(3)iterator era转载 2013-02-23 14:17:13 · 1692 阅读 · 0 评论 -
c++ string 的函数replace()用法
basic_string::max_size返回string 能放的最大元素个数。(不同于capacity)size _ type max _ size( ) const;basic_string ::size_type cap, max;cap = s.capacity ( );max = s.max_size ( ); // max=429496转载 2013-02-23 13:20:50 · 776 阅读 · 0 评论 -
C++ string assign()赋值常用方法
C++ string assign()赋值常用方法函数assign()常用在给string类变量赋值.常用方法有:1,直接用另一个字符串赋值.如str2.assign(str1);即用str1给str2赋值.2,用另一个字符串的一个子串赋值如str3.assign(str1, 2, 3);3,用一个字符串的前一段子串赋值;如str4.转载 2013-02-23 14:25:56 · 88669 阅读 · 1 评论 -
C++ 中string.find() 函数的用法总结(转载)
#include #include using namespace std;void main(){[cpp] view plaincopy ////find函数返回类型 size_type string s("1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8ha9i"); string flag;转载 2013-02-23 11:12:01 · 788 阅读 · 0 评论 -
c++ string 类的原型
#include#includeusing namespace std;class String{friend ostream& operatorpublic:String(const char* psz = NULL);String(const String& str);~String();String& operator=(const String& s转载 2013-02-22 15:38:44 · 3243 阅读 · 0 评论 -
正确使用STL-MAP中Erase函数
#include #include #include string>using namespace std ;int main(void) { mapint, string> m ; m.insert(pairint, string>(1, "abc")) ; m.insert(pairint, string>(2, "def")) ;转载 2013-05-09 15:13:06 · 808 阅读 · 0 评论