Skip to content

Instantly share code, notes, and snippets.

@dz0
Last active October 16, 2017 03:29
Show Gist options
  • Select an option

  • Save dz0/9254774061e2d0ecc7a589aa5ebd7c0d to your computer and use it in GitHub Desktop.

Select an option

Save dz0/9254774061e2d0ecc7a589aa5ebd7c0d to your computer and use it in GitHub Desktop.
ktug string intro pavyzdžiai
// https://repl.it/MftC/1
#include <iostream>
#include <string>
using namespace std;
char simb = 'a'; // simboliui - viengubos kabutes
string txt = "Labas rytas"; // tekstui - dvigubos
// simb nr.: 0123456789..
int main()
{
cout << txt << endl;
int kur = txt.find("as"); // grąžina fragmento pradžios vietą/nr, o jei fragmento nėr, -1
cout << "\"as\" yra vietoje: " << kur << endl;
string dalis = txt.substr(6, 3); // nuo kur (6), kiek simbolių (3) "atpjaut"
cout << " txt.substr(6, 3): " << dalis << endl;
cout << "teksto ilgis: " << txt.size() << endl; // arba txt.length()
cout << "q didžioji: " << (char) toupper('q') << endl; // reik typecast -- duomenu tipo patikslinimo
for (int i = 0; i < txt.length(); i++)
{
// simbolių kodai/numeriai: http://www.asciitable.com/index/asciifull.gif
cout << txt[i] << " simbolio kodas yra "<< (int)txt[i] << endl;
// verčiam didžiosiom
txt[i] = toupper(txt[i]);
}
cout << "Pavertus didžiosiom: " << txt << endl;
// tekstą galima palyginti (naudinga rikiavimui pagal abėcėlę)
if ("Romas" > "Rokas") cout << "Romas daugiau.. " << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment