string 与 char关于在字符串中 加入‘\0’的区别

#include <iostream>
#include<string>
using namespace std;
int main() 
{	
	string s = "12345";
	s[2] = '\0'; 
	int a = s.find('5');
	cout << a << endl;
	cout << s << endl;
	char p[] = "12345";
	p[2] = 0;
	cout << p << endl;
	getchar();
	return 0;
}

结果如下:

4
12 45
12


猜你喜欢

转载自blog.csdn.net/znzxc/article/details/80818572