【♂Not The Triumph♂O(∩_∩)O哈哈~But The Struggle♂】

竞赛决不是捷径,它只是另一种艰辛的生活方式。得到与失去,只有时间会去评判;成功与失败,只有历史能去仲裁。我不会永远成功,正如我不会永远失败一样

  C++博客 :: 首页 :: 联系 ::  :: 管理
  6 Posts :: 239 Stories :: 25 Comments :: 0 Trackbacks

常用链接

留言簿(7)

我参与的团队

搜索

  •  

积分与排名

  • 积分 - 104816
  • 排名 - 233

最新评论

阅读排行榜

评论排行榜

//泛函数排序sort的使用
#include<iostream>
#include
<vector>
#include
<algorithm>
using namespace std;
bool cmp(const long &x,const long &y)
{
//ture不交换 false交换,sort默认是升序。此程序为降序
    if (x>y) return 1;
    
else return 0;
}
int main()
{
    vector
<long> v(10);
    
int i;
    
for (i=0;i<10;i++) v[i]=i;
    vector
<long>::iterator j;
    
for (j=v.begin();j<v.end();j++)
       cout
<<*j<<' ';
    cout
<<endl;
    sort(v.begin(),v.end(),cmp);
    
    
for (j=v.begin();j<v.end();j++)
      cout
<<*j<<' ';
    cout
<<endl;
    system(
"pause");
    
return 0;

 

//C++容器向量大小的相关函数
#include<iostream>
#include
<vector>
#include
<algorithm>
using namespace std;
int
 main()
{
    vector
<long> v(10
);
    
int
 i;
    
for (i=0;i<=9;i++) v[i]=
i;
    cout
<<
endl;
    cout
<<"容器大小:"<<v.size()<<
endl; 

    cout
<<"容器的空与不空:"<<v.empty()<<
endl; 

    v.clear(); 

    cout
<<"容器大小:"<<v.size()<<
endl; 

    cout
<<"容器的空与不空:"<<v.empty()<<
endl;
    system(
"pause"
);
    
return 0
;

 

/*C++ string 的基本操作
+运算,length(),比较函数
连接函数
*/

#include
<string>
#include
<iostream>
#include
<algorithm>
using namespace std;
int
 main()
{
    
string s1="abcd"
;
    
string s2="1234"


    cout
<<s1.length()<<
endl;
    
    s1.append(s2);
//等价=> s1=s1+s2;

    cout<<s1<<endl;
    
    cout
<<
endl;
    
    cout
<<s1.length()<<
endl;
    system(
"pause"
);
    
return 0
;

//string 的替换和插入函数(replace)
#include<string>
#include
<iostream>
#include
<algorithm>
using namespace std;
int
 main()
{
    
string
 s,s2;
    s
="abcd123456"
;
    s2
=
s;
    s.replace(
3,1,"good"
);
    
/*
如果replace的第一个数值是从哪个位置的前面开始插入一个字符或字符串
    第二个参数是替换几个,1就替换开始插入位置把替换的个数字符换成要替换的字符的前几个如上例就是把d换成了g,再插入ood再后面,第三的参数就是插入的字符啦
*/

    cout
<<s<<endl;
    cout
<<
endl;
    
//再了个例子:

    s2.replace(3,3,"good");
    cout
<<s2<<
endl;
    system(
"pause"
);
    
return 0
;


posted on 2009-03-28 18:31 开拓者 阅读(729) 评论(0)  编辑 收藏 引用 所属分类: C/C++ STL 学习

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理