c 字符串函数 C++字符串操作.doc
文本预览下载声明
c 字符串函数 C++字符串操作
导读:就爱阅读网友为您分享以下“C++字符串操作”的资讯,希望对您有所帮助,感谢您对92的支持!
字符串操作是一个不小的主题,在标准C++中,string字符串类成为一个标准,之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下的需要.
下面我们首先从一些示例开始学习下string类的使用. 1)
#include lt;stringgt;
#include lt;iostreamgt;
using namespace std;
void main()
{
string s(quot;hehequot;);
string s1=quot;abcdquot;;
coutlt;lt;slt;lt;” “lt;lt;s1lt;lt;endl;
}
2)
#include lt;stringgt;
#include lt;iostreamgt;
using namespace std;
void main()
{
char chs[] = quot;hehequot;;
string s(chs);
coutlt;lt;slt;lt;endl;
显示全部