|
#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;
}
|
|