string相关

int main()
{
	// world替换成 xxxxxxxxxxxxxxxxxxxxxx
	string s1("hello world hello bit");
	s1.replace(6, 5, "xxxxxxxxxxxxxxxxxxxxxx");
	cout << s1 << endl;

	s1.replace(6, 23, "yyyyy");
	cout << s1 << endl;

	// 所有空格替换成20%
	string s2("hello world hello bit");
	string s3;
	for (auto ch : s2)
	{
		if (ch != ' ')
		{
			s3 += ch;
		}
		else
		{
			s3 += "20%";
		}
	}

	s2 = s3;
	cout << s2 << endl;
	cout << s2.c_str() << endl;

	// c的一些接口函数配合
	string filename = "test.cpp";
	filename += ".zip";

	FILE* fout = fopen(filename.c_str(), "r");

	return 0;
}

C_str:当在C++中想要查看C中的一些文件或者代码时,可以使用这个进行打开查看

相关推荐

  1. Spring相关

    2024-07-19 18:28:08       36 阅读
  2. Spring MVC相关

    2024-07-19 18:28:08       37 阅读
  3. Spring相关实战

    2024-07-19 18:28:08       29 阅读
  4. Spring事务相关

    2024-07-19 18:28:08       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 18:28:08       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 18:28:08       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 18:28:08       58 阅读
  4. Python语言-面向对象

    2024-07-19 18:28:08       69 阅读

热门阅读

  1. 学术资源网站

    2024-07-19 18:28:08       23 阅读
  2. MySQL 删除重复记录

    2024-07-19 18:28:08       18 阅读
  3. go exporter开发 第一篇

    2024-07-19 18:28:08       17 阅读
  4. ubuntu23安装tensorRT步骤记录

    2024-07-19 18:28:08       18 阅读
  5. Unable to connect to Redis] with root cause

    2024-07-19 18:28:08       18 阅读