找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 24|回复: 0

C++ 程序1-9

[复制链接]

31

主题

13

回帖

151

积分

管理员

积分
151
发表于 2025-1-27 13:11:42 | 显示全部楼层 |阅读模式
#include <iostream>
#include <string>

using namespace std;

int main()
{

    string str="1234";
    if(str.empty())
        cout << "str is NULL" << ".length="<< str.length() << endl;
    else
        cout << "str is not NULL" <<".length="<< str.length()<< endl;

    str= str.append("abcdefg");

if(str.empty())
        cout << "str is NULL" << ".length="<< str.length() << endl;
    else
        cout << "str is not NULL" <<".length="<< str.length()<< endl;





  cout<< "str is " << str << ",size=" <<str.size()<< endl;
   const char *p = str.c_str();//把C_str字符串给P指针

   cout << "p="<< p <<endl;
   cout <<"find:"<< str.find("cd",0)<<endl;
   cout <<"find:"<< str.find("cd",12)<<endl;
   string strl = str.insert(4,"ABC");
   cout << strl << endl;


    return 0;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|辅助技术分享 ( 鄂ICP备18031529号-1|浙公网安备33011002015680号 )

GMT+8, 2025-2-5 15:54 , Processed in 0.091663 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表