zoukankan      html  css  js  c++  java
  • std::string 杂记

    std::string strSubtitle =@"";
    
     
    
     if( ! strSubtitle.empty() ) //判断字符串的是否为空
    
        {
    
            CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 22);
    
            addChild(l, 1);
    
            l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) );
    
        }    
    
    string的追加
    
     
    
           std::string s1 = "hello";
    
        std::string s2 = "world";
    
        std::string s3 = s1 + "," + s2 +"!\n";
    
     CCLog("%s",s3.c_str());
    
    也可以 sprintf("%d.png", i);搞定
    
    string 比较
    
     
    
    if (s1=="hello") {
    
            CCLog("一样");
    
     }
    
     
    
    string遍历节点
    
     
    
     
    
     for(int i = 0 ; i < s3.size(); i ++){
    
            CCLog("%c\n",s3[i]);
    
        }
    
     
    
    //
    
     
    
     int index = str.find("baidu");//查找字符串字母位置
    
     str.replace(index, 5, "sain");//把规定字符串替换
    
      CCLog("%s",str.c_str());
    
    //把char 类型转数组 通过","
        char*gs;
    
        int a[2];
    
        std::string testString= "1,2,3";
    
        char *order;
    
     
    
        strcpy(gs, testString.c_str());
    
        order = strtok (gs,",");
    
        int i=0;
    
        while(order!=NULL) {
    
            CCLog( "%s",order );
    
            int aa= atoi(order);
    
            CCLog("%d",aa);
    
            order = strtok(NULL,",");
    
            a[i]=aa;
    
             i++;
    
        }
    
        CCLog("%d",a[1]);
  • 相关阅读:
    Linux
    python中元类
    POJ 1182 食物链
    POJ 1733 Parity game
    top 介绍
    周记 2014.8.31
    windows10配置python
    oracle执行update时卡死问题的解决办法
    An Easy Introduction to CUDA C and C++
    super()
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3019900.html
Copyright © 2011-2022 走看看