Last active
October 16, 2017 03:29
-
-
Save dz0/9254774061e2d0ecc7a589aa5ebd7c0d to your computer and use it in GitHub Desktop.
ktug string intro pavyzdžiai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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