添加字符串操作
This commit is contained in:
parent
b648bb02e9
commit
a46fb16beb
@ -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
29
base/string/smrtptrs.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user