-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringFeatures.cpp
More file actions
29 lines (21 loc) · 894 Bytes
/
stringFeatures.cpp
File metadata and controls
29 lines (21 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
using namespace std;
void computeFeatures(string); //declare function prototype
int main() {
string text = "C++ is fun";
computeFeatures(text); //call function
text += " for everyone!"; //concatenate string to string (bigger)
computeFeatures(text); //call function
text = " C++ fun!"; //concatenate string to string (smaller)
computeFeatures(text); //call function
text.clear(); //clear string
computeFeatures(text); //call function
return 0;
}
void computeFeatures(string text) { //define declared function
cout << endl << "String: " << text << endl;
cout << "Size: " << text.size(); //size of string
cout << " Capacity: " << text.capacity(); //capacity is the maximum size of the string
cout << " Empty?: " << text.empty() << endl; //empty() returns true(1) if string is empty
}