-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-strings.cpp
More file actions
23 lines (16 loc) · 813 Bytes
/
02-strings.cpp
File metadata and controls
23 lines (16 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main() {
string phrase = "Giraffe Academy"; // Al igual que ocurren en Java, un string en C++ es un objeto y tiene métodos.
cout << "Hello" << endl; // endl = '\n'
cout << phrase << '\n';
cout << phrase.length() << endl;
cout << phrase[0] << ", " << phrase[2] << endl;
phrase[0] = 'B'; // En C y en C++, los string son mutables y pueden modificarse.
cout << phrase << endl;
cout << phrase.find("Academy") << endl; // Encuentra desde el principio.
cout << phrase.find("Academy", 0) << endl; // Encuentra desde el principio. Equivalente a "phrase.find("Academy")".
string subPhrase = phrase.substr(8, 3); // Dame la subcadena de texto de longitud 3 que empieza en la posición 3.
cout << subPhrase;
return 0;
}