Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

STRING LENGTH CODE

#include <iostream> #include <string> // include for C++ standard string class using namespace std; int main() { string stringA = "C++"; string stringB = "Is Cool"; cout << "Length of stringA = " << stringA.length() << endl; cout << "Length of stringB = " << stringB.length() << endl; return 0; } /* Length of stringA = 3 Length of stringB = 7 */

UPPER CASE

#include <iostream> using namespace std; int main () { std::string some_name = "some name"; for (int i = 0; i < (some_name.size() - 1); ++i) { char some_char = some_name[i]; cout << toupper (some_char); } cout << endl;

cin.get(); return 0; }

LOWER CASE

#include <iostream> using namespace std; int main () { std::string some_name = "some name"; for (int i = 0; i < (some_name.size() - 1); ++i) { char some_char = some_name[i]; cout << tolower (some_char); } cout << endl; cin.get(); return 0; }

Concatenate two strings

#include <iostream> #include <string> using namespace std; int main() { string str1("A"); string str2("B"); string str3("G"); string str4; cout << " cout << " cout << " str1: " << str1 << endl; str2: " << str2 << endl; str3: " << str3 << "\n\n";

// Concatenate two strings.

str4 = str1 + str3; cout << "str4 after begin assigned st1+str3: " << str4 << "\n\n"; return 0; }

RESERVE STRING

#include <iostream> #include <string> using namespace std; int main () { string str = "Anatoliy Urbanskiy"; cout << str.reverse() << endl; return 0; }

You might also like