添加字符串操作

This commit is contained in:
zhuyijun 2021-09-21 18:36:41 +08:00
parent b648bb02e9
commit a46fb16beb
3 changed files with 40 additions and 2 deletions

View File

@ -82,6 +82,7 @@ add_executable(constcast exception/constcast.cpp)
add_executable(str1 string/str1.cpp)
add_executable(strfile string/strfile.cpp)
add_executable(hangman string/hangman.cpp)
add_executable(str2 string/str2.cpp)
add_executable(vect1 stl/vect1.cpp)
add_executable(vect2 stl/vect2.cpp)
add_executable(vect3 stl/vect3.cpp)

29
base/string/smrtptrs.cpp Normal file
View File

@ -0,0 +1,29 @@
//
// Created by nicemoe on 2021/9/18.
//
#include <iostream>
#include <string>
#include <memory>
using namespace std;
class Report{
private:
string str;
public:
Report(const string s) :str(s){
sout <<"Object created!"<<endl;
}
~Report(){
cout<<"Object deleted!"<<endl;
}
void comment(){
cout<<str<<endl;
}
};
int main() {
{
auto_ptr<Report> ps (new Report("using "))
}
return 0;
}

View File

@ -10,9 +10,17 @@ int main() {
string empty;
string small = "bit";
string larget = "Elephants are a girl's best friend";
string larger = "Elephants are a girl's best friend";
cout <<"Sizes:\n";
cout <<""
cout <<"\tempty: "<<empty.size()<<endl;
cout <<"\tsmall: "<<small.size()<<endl;
cout <<"\tlarger: "<<larger.size()<<endl;
cout <<"\tCapacities: "<<endl;
cout <<"\tempty: "<<empty.capacity()<<endl;
cout <<"\tsmall: "<<small.capacity()<<endl;
cout <<"\tlarger: "<<larger.capacity()<<endl;
empty.resize(50);
cout<<"Capacity after empty.reserve(50): "<<empty.capacity()<<endl;
return 0;
}