算法笔记-字符串

字符串拼接

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(int argc,char * argv[]){
    string s="abc";

    // ----- 字符串拼接字符串 ----- 

    s+=to_string(10); 
    s.append("def");
    s.append(to_string(11));
    printf("%s",s.c_str());

    // -----  字符串拼接字符 ----- 

    s+='g';
//  s.append('h'); error 

    //  ----- 字符串拼接单个数字 ----- 

//  s.append(1); error
    s+=2+'0';
//  s.append(3+'0'); error
    s.append(to_string(4));
    printf("%s",s.c_str());


    //  ----- 字符串拼接多位数字 ----- 

//  s+=12+'0'; error ascii码中 没有12这个字符,12+'0' 不是'12' 
//  s.append(12);error
//  s+12; error
    s.append(to_string(12));
    s+=to_string(234);
    printf("%s",s.c_str());
    return 0;
} 

原文链接: https://www.cnblogs.com/houzm/p/13335185.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    算法笔记-字符串

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/367982

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 下午6:09
下一篇 2023年3月2日 下午6:10

相关推荐