首页 > 编程语言 > 详细

C++ STL string

时间:2021-06-29 00:14:52      阅读:31      评论:0      收藏:0      [点我收藏+]

1. STL中的 string 类型支持类似java中的直接进行字符串相加,但是不支持相减

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str = "Hello World";
    str += " I am comming!";
    cout << str << endl; //只能+=,不能-=

    int a = 123456;
    str = to_string(a); //c++11引入的,编译时需要加上-std=c++11
    cout << a << endl;

    return 0;
}

$ g++ std_string.cpp -o pp -std=c++11
$ ./pp
Hello World I am comming!
123456

 

【C++ STL String】常用操作: https://www.jianshu.com/p/90584f4404d2
std:string: https://blog.csdn.net/L_insting/article/details/110149869

 

C++ STL string

原文:https://www.cnblogs.com/hellokitty2/p/14946291.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!