Mudanças entre as edições de "Exemplos de operações com strings no C++"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
Linha 46: Linha 46:
  
 
=Apagando caracteres da string=
 
=Apagando caracteres da string=
 +
 +
Ver [https://www.geeksforgeeks.org/stdstringerase-in-cpp/ link]
  
 
<syntaxhighlight lang=c++>  
 
<syntaxhighlight lang=c++>  

Edição das 12h29min 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;
}