Mudanças entre as edições de "Exemplos de operações com strings no C++"
Ir para navegação
Ir para pesquisar
Linha 64: | Linha 64: | ||
texto.erase(2); | texto.erase(2); | ||
+ | |||
+ | cout << texto << endl; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang=c++> | ||
+ | |||
+ | #include <string> | ||
+ | #include <iostream> | ||
+ | #include <string.h> // para função de string C | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() { | ||
+ | string texto1 = "Santa"; | ||
+ | string texto2 = "Catarina"; | ||
+ | string texto; | ||
+ | |||
+ | texto = texto1 + ' ' + texto2; | ||
+ | |||
+ | texto.erase(2,3); | ||
cout << texto << endl; | cout << texto << endl; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição atual tal como às 12h32min de 19 de abril de 2022
Iniciando Strings
Comparando Strings
Ver link
#include <string>
#include <iostream>
#include <string.h> // para função de string C
using namespace std;
int main() {
string texto1 = "delta";
string texto2 = "betaaaa";
if(texto1>"beta") {
cout << "delta é maior..." << endl;
}
}return 0;
}
Concatenando strings
#include <string>
#include <iostream>
#include <string.h> // para função de string C
using namespace std;
int main() {
string texto1 = "Santa";
string texto2 = "Catarina";
string texto;
texto = texto1 + ' ' + texto2;
cout << texto << endl;
}
Apagando caracteres da string
Ver link
#include <string>
#include <iostream>
#include <string.h> // para função de string C
using namespace std;
int main() {
string texto1 = "Santa";
string texto2 = "Catarina";
string texto;
texto = texto1 + ' ' + texto2;
texto.erase(2);
cout << texto << endl;
}
#include <string>
#include <iostream>
#include <string.h> // para função de string C
using namespace std;
int main() {
string texto1 = "Santa";
string texto2 = "Catarina";
string texto;
texto = texto1 + ' ' + texto2;
texto.erase(2,3);
cout << texto << endl;
}