24 lines
746 B
C++
24 lines
746 B
C++
// str2.cpp -- capacity() and reserve()
|
|
#include <iostream>
|
|
#include <string>
|
|
int main()
|
|
{
|
|
using namespace std;
|
|
string empty;
|
|
string small = "bit";
|
|
string larger = "Elephants are a girl's best friend";
|
|
cout << "Sizes:\n";
|
|
cout << "\tempty: " << empty.size() << endl;
|
|
cout << "\tsmall: " << small.size() << endl;
|
|
cout << "\tlarger: " << larger.size() << endl;
|
|
cout << "Capacities:\n";
|
|
cout << "\tempty: " << empty.capacity() << endl;
|
|
cout << "\tsmall: " << small.capacity() << endl;
|
|
cout << "\tlarger: " << larger.capacity() << endl;
|
|
empty.reserve(50);
|
|
cout << "Capacity after empty.reserve(50): "
|
|
<< empty.capacity() << endl;
|
|
// cin.get();
|
|
return 0;
|
|
}
|